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 two, Cache Data to Device, you followed the best practice that dictates we replicate and cache server-side entities to the client. That practice allows you to reduce the number of network requests and support an “offline” mode. In part three, you will prepare your application to retrieve data from your Salesforce instance by following these steps:
- Create a SalesforceUser entity.
- Recover the user’s access token.
- Verify the access token.
Watch the video for the full step-by-step process or read along for an abridged description of the video’s content.
1. Create a SalesforceUser Entity
Add a new entity, SalesforceUser, that maps an OutSystems user to their respective Salesforce user. The entity requires two attributes: an id and an AccessToken. The identifier found in SalesforceUser will correspond to the identifier belonging to its respective OutSystems user, and you will use the user’s id to filter results for their Salesforce data in the next step.
2. Recover the User’s Access Token
In the DoLogin action, invoke the SalesforceToken_Get action provided by the Salesforce connector. This action does precisely as the name indicates, and you will use the results to create or update a SalesforceUser.
Recover a single SalesforceUser by filtering for an identifier that matches the authenticated OutSystems user. Assign the authenticated user’s id and the Access_Token property (returned by SalesforceToken_Get) to the SalesforceUser’s id and AccessToken, respectively. Lastly, perform a CreateOrUpdateSalesforceUser action.
3. Verify the Access Token
Publish your changes, logout, and reauthenticate to trigger the DoLogin flow. After you’ve logged back in, browse your server-side SalesforceUser data—you should see precisely one entry that maps your OutSystems user id to an access token.
In the next part of this tutorial, you will create local synchronization actions. These actions support offline mode—they automatically create, update, and delete entities from the server at critical entry points: on app open, on connection reestablished, and more.