Force.com Mobile AppDev - Part 1

Abstract

Many Devices - One Platform

This tutorial provides an introduction to Force.com Mobile application development. It shows how to deploy a Force.com application to a mobile device, and sketches the additional functionality that you get out of the box. Follow along, and you will learn how to expose database objects on your mobile device and take advantage of the resulting user interface.


Introduction to the Force.com Mobile Platform

The Force.com mobile platform allows you to build and deploy custom mobile applications that conform to your already defined Force.com application. With point-and-click simplicity, you can build complex mobile applications that provide an out-of-the-box moblie extension to your Force.com applications.

By utilizing Apex and Visualforce, the Force.com mobile platform can also be used to develop sophisticated, device-specific applications that can exploit the features of advanced devices - such as the Motorola family of handheld mobile computers, the Apple iPhone and the enterprise standard RIM Blackberry.

This tutorial shows how to get started by creating a mobile configuration, to expose data to these devices.

Developing for Force.com Mobile

New Mobile Configuration

What does it mean to "develop a mobile Force.com app?" At a fundamental level, once you have defined your data model (standard and custom objects, relationships) your app can easily be mobilized with a few configuration steps. To start off, this tutorial shows how to mobilize the Account object from your Developer Edition environment.

To configure mobile access click Setup|Mobile Administration|Mobile Configurations. Click the button "New Mobile Configuration" to create a new configuration. If you are following along with your Developer Edition, we will be setting up your configuration as shown in the screenshot to the right.

  1. Enter a name for your mobile configuration
  2. Select the check box to make this configuration Active
  3. Add your current user to the Assigned Members shuttle list
  4. Click Save

With this (and any) mobile configuration, you will be able to manage and restrict what data is pushed to the mobile device, configure mobile object properties, set up tabs and views.

The next step in setting up a mobile configuration is to decide what data (and objects) to provide to the mobile user, and what tabs to expose on the mobile device. These two configuration aspects define what your mobile application will do, and what data will be provided to the user by default.

Mobile Data Sets

Edit Data Sets

A data set is a defined set of filters (by object) that allow you to restrict the data that is accessed by the device. For each object, you provide a set of filter conditions and a max record limit. If you wish, you can specify not to push any data to the device for a particular object - Choosing the option Search Only will require the user to search for records they wish to sync to their mobile device.

The edit Data Set page also allows you to test your data set filters with a utility at the bottom of the page. This is useful if you have complex filters and wish to model how the filter will function with individual users and profiles.



Mobile Object Properties

With your data set defined, the next consideration for you mobile app affects the layouts that will be automatically generated as well as what data permissions to allow your users.

Salesforce Mobile respects all data access permissions and sharing rules defined for the organization. In the Mobile Object Properties section of your configuration page, you will see one entry per object referred to in your Data Set definition. For each of these objects, you can further limit the ability for the user to Create, Edit and Delete records for this object.

Object Permissions


Object Properties

When displaying records, Salesforce Mobile will respect page layouts defined for record types and user profiles. To further limit which field are displayed by the mobile client's object renderer, you can exclude fields from being displayed for each object.

Mobile Tabs

Not all objects need tabs, and some tabs may not have objects behind them (such as Visualforce Mobile tabs). To affect which objects in the Data Set have tabs on the mobile device and which Visualforce Mobile tabs appear, edit the Mobile Tabs section. You can also change the order of the tabs as they appear on the device.

For more information on mobile configuration, consult the Salesforce Mobile Implementation Guide.

For reference, you can set up your configuration options as shown in this screenshot of my mobile config page. Note that I chose to exclude the majority of Account fields, and only enable Account Number, Billing Address, Customer Priority and Rating.

We are now done with the mobile set up and configuration. With this basic configuration, you have now created your first mobile application.

Mobile Client Installation

Installation of the Salesforce Mobile client varies by device.

iPhone:

  1. Go to the Apple iPhone App Store (on your device, or within iTunes)
  2. Search for Salesforce Mobile
  3. Follow the instructions in the appstore to install on your device

BlackBerry and Windows Mobile:

  1. Point your mobile browser to mobile.salesforce.com/setup
  2. Select the link Click here to download the client

Once you download and launch the application, you'll be asked to supply the username and password for your developer edition environment that you used above.

Testing the Application

To test out your Force.com development on the iPhone, you can either setup the iPhone mobile client (consult the Salesforce Mobile User Guide for iPhone for more information), or you can install the Force.com iPhone Simulator for Mac OS. If you are a Mac user, I recommend using the iPhone Simulator for your dev work.

(Windows users can download a BlackBerry simulator. Although the following examples and screenshots focus on the iPhone.)

Here are two screenshots of the application running in the simulator:

Image:Simulator-app.png

Default Application Behavior

Looking at the image above (or reviewing your application in your simulator), you can see that you get a lot of rich application functionality for very little effort. By exposing the object (Accounts) in the mobile configuration, you can leverage all of the business rules and system behavior that you may have developed in your existing Force.com application. This includes:

  • Workflow
  • Assignment rules
  • Data Validation rules
  • Apex triggers

Built in functionality

The Force.com Mobile client comes with built-in functionality that is tuned to enriching the mobile user experience, as well as providing for automated data management.

  • Recents tab: Displays a list of recent records that you recently viewed on the device.
  • Search tab: Allows you to search for records associated with objects exposed in your mobile configuration. In our example, we have only exposed Accounts - so, we will only be able to search on Accounts. The search function will fetch results from the cloud, and compare against local records on your device. This is a useful way of pulling down data that may not be in your pre-defined data set (part of your mobile configuration).
  • App Info: This is the user's mobile control panel that allows you to:
    • Sync Now - Force a data sync with the server
    • Refresh All Data - Refresh data and meta data. Useful after making changes to your mobile configuration
    • Clear Searched Records - Remove records from Search tab
    • Clear Recent Items - Reset Recents tab to not show any recent records
    • Send Support Logs - used for troubleshooting
    • Erase All Data - This wipes your data and resets your client to its original state. Use this when you want to use this device with another org (you must first remove this device from your previous org - see Salesforce Mobile Implementation Guide for more information).

Custom tabs

Custom Tabs

When you defined the mobile tabs in your mobile configuration, you selected the objects that you wished to enable on the mobile device. For this tutorial, you selected to mobilize the Accounts object - but you could have chosen any custom object or other standard object as well. In order to mobilize an object, you must first include the object (and requisite data filter) in you Data Set as part of your mobile configuration. To see the tab, you must add it to the set of Mobile Tabs in the mobile configuration.

If we look carefully at the user interface of the mobile client on the iPhone, you can see that there is limited real estate to display tabs at the bottom of the screen. For this reason, the Force.com Mobile client will display your first 2 tabs defined in your mobile configuration (Mobile Tabs), with the remaining objects being accessed from a list behind the More... tab. The More... tab is only displayed when you have 3 or more objects exposed in your mobile configuration. Each user can customize which tabs are displayed in the tab bar by selecting More... and the Edit button in the upper right corner. Then drag the tabs you want into the tab bar.


Summary

This tutorial provides an introduction to Force.com Mobile application development. It shows how to deploy a Force.com application to the iPhone (and similarly to all supported mobile devices), and sketches the additional functionality that you get out of the box. Future articles will look at Visualforce Mobile, which lets you expose Visualforce pages to the mobile devices, and hence tailor the look and feel of the user interface.

References

About the Author

Mike Kreaden is a Partner Evangelist at salesforce.com, helping CRM application developers deliver killer commercial apps for the Force.com platform.