In this multi-part tutorial, you will discover how to seamlessly integrate your Salesforce data into an OutSystems mobile application. You will learn to incorporate the Salesforce connector, authenticate with Salesforce, pull data from Salesforce’s servers, and cache the data for use in your mobile application.
In part four, Synchronize Client with Server, you performed a neat trick that helped you quickly establish synchronization actions for your mobile client data. The actions created by Service Studio follow best practices, and you performed that odd shortcut to discover this powerful feature. In this fifth and final part, you will begin to synchronize data with Salesforce and display it on the device by following these steps:
- Enable LocalLeadEntity synchronization
- Prepare the user interface
- Assign access token to the Salesforce connector
Watch the video for the full step-by-step process or read along for an abridged description of the video’s content.
1. Enable LocalLeadEntity Synchronization
You’ve prepared your synchronization actions for LocalLeadEntity objects, but these actions are currently unused. To employ them, begin by navigating to the OfflineDataSyncConfiguration action. This local action permits you to choose when your application executes the OfflineDataSync action, and thereby synchronizing your local data with your server. In this action, we’ve enabled synchronization for the first three application triggers: SyncOnOnline, SyncOnLogin, and SyncOnResume. The comments assigned to each trigger explain precisely when the synchronization will occur — you may enable synchronization on fewer or more triggers.
With synchronization enabled, edit the OfflineDataSync action. Drag the previously-generated SyncLocalLeadEntities action onto the execution path — we’ve placed ours immediately after the ServerDataSync action. This placement guarantees that your application will synchronize LocalLeadEntity objects whenever an offline synchronization occurs.
2. Prepare the User Interface
Add a local storage aggregate to the Home screen to recover every LocalLeadEntity from your cache. Then drag the aggregate onto the user interface to generate a default list entry. In our example, we’ve modified the interface to place the first, middle, and last name on a single line, in bold. We’ve removed the generated checkbox entries for IsFromServer, IsModified, and IsActive (these booleans act as flags for offline synchronization and need not be visible to users).
We’ve also moved the title and company attributes to a single line beneath the person’s name. With that final touch, we’ve prepared our interface. However, you may arrange the data in any configuration you wish.
3. Assign Access Token to the Salesforce Connector
In our infinite wisdom, we are still capable of making the occasional mistake. In an earlier part of this tutorial, we retrieved the user’s Salesforce access token and stored it in our database. However, we forgot to take an additional step: setting the access token before invoking a Salesforce API. In this step, we will rectify this mishap to avoid any authentication errors before proceeding.
Create a server action and name it InitializeSalesforceConnection. In this action, create an aggregate that recovers a single SalesforceUser by filtering the Id attribute that matches the current user’s identifier:
SalesforceUser.Id = GetUserId()
With the user’s SalesforceUser entity retrieved, you can perform the next step. Invoke the SalesforceToken_Set action found in the SalesforceREST connector. This will set the access token for any requests which proceed InitializeSalesforceConnection. Assign the access token parameter to the stored token found within the SalesforceUser entity, and save your progress.
Lastly, add your InitializeSalesforceConnection to the SyncLeadEntities action immediately before the first Salesforce action; in our case, this is LeadCreate. With everything set, you can now publish your changes, logout, and re-authenticate. Assuming you requested an OfflineDataSync on login, you will now see beautiful Salesforce lead data populate your home screen!
Congratulations are in order for completing this tutorial, good reader. After finishing these five parts, you now have an understanding of mobile design patterns, particularly those that revolve around data synchronization. You’ve learned best practices that enable reduced battery consumption, limited network demands, and a persistent offline mode. Couple these properties together to provide a seamless and valued mobile experience in every application you build.