What we are going to build?
In this tutorial, you’ll learn how to integrate Salesforce into your Appery.io app to create contacts.
Before you begin
Tutorial level: intermediate.
Registering & creating an app
If you already have a Salesforce developer account, and have created connected applications there, skip this section and go to creating services in Appery.io to integrate your applications. You need a Consumer Key in your Appery.io app.
To register on salesforce.com as a developer, open https://events.developerforce.com/signup. The developer can call the REST API provided by Salesforce. After confirming the registration, open this page where you can create a connected app. This app sends requests for access, and gets access to the objects for which you are going to generate services in Appery.io:
The Callback URL is the standard Appery.io page that receives data from Salesforce, and saves it in the client session:
OAuth Scopes should have at least the Access and manage your data (api) value. Later, you may give greater scope to your app if necessary.
Creating services in Appery.io
You can create a new project or use an existing one.
To integrate your Appery.io project with Salesforce:
1. Select CREATE NEW > Salesforce Services.
The first time, you’ll need to log in and allow access to your data.
Note: You will need to allow pop-up windows in your browser.
2. The login window closes automatically, and you’re redirected to the “Salesforce services” popup, where you can check the services you need.
3. Click “New channel” to create Proxy channel.
6. Open the Salesforce_settings service, and for the client_id parameter, enter your Consumer Key value (copy it from the Salesforce application page).
8. Copy the Authorization header value for salesforce_access_token and the Salesforce instance URL value for salesforce_instance_url. Paste them to the according parameters in Salesforce_settings.
Note: while defining Salesforce service integration in appery.io to query or update an entity on Salesforce, additional request or response parameters cannot be passed to the service by default. Instead, a JS statement to specify the parameters should be written.
Important: After the service has been tested, remove the values of the salesforce_instance_url and salesforce_access_token parameters in Salesforce_settings, otherwise your app won’t work correctly.
Building the mobile UI
For this app, you need two pages: startScreen and addContact.
1. The startScreen has two buttons:
This function is defined in the custom Salesforce_utils file.
- contactButton with a navigate to page event; navigating to the addContact page.
The addContact page can have fields for any contact information you want to save. The fields are limited only by the parameters in the Salesforce_Contact_create_service in Request view.
4. In mapping to Birthday parameter click “JS” to add the following JS:
var parts = value.split("/");
return parts + "-" +parts + "-" +parts;
5. Click “Save and return”.
Testing the app
After you’ve completed the steps, save the project and click “Test.”
You can add any other Salesforce services to your Appery.io application in the same way.