Rest API Salesforce Integration
Creating Salesforce account
Follow below steps to create Salesforce account:
-
Fill in the details.
-
Click Sign me up button, you will receive an email for verification and password setup.
-
Setup Password and security question and login to Salesforce.
-
Once logged in, you will be presented with Lightning view, change to classic view from user icon (at the top right corner).
Setting Up Salesforce
To Setup connected Salesforce App follow below steps:
-
Go to Setup icon (on top right).
-
Once on the setup window expands, in the left panel under Build Section go to Create → Apps.
-
On the App Window, under Connected Apps section select New to register a new Connected App.
-
On register New Connected App window, fill in the required fields.
-
In the API (Enable OAuth Settings) section click on Enable OAuth Settings checkbox, (to connect with our Sales org we have 2 options Authorization code flow and username Password flow, Callback URL mentioned under (Enable OAuth Settings) is relevant if we use Authorization code flow to get the Authentication token ). OAuth Scope defines the limit to which you want to set the access of external users on the Sales Org (we are using Access and manage your data(api) you can set scope according to your own requirements.)
-
Once the details are filled, click Save. Continue on the next window and wait for the App to be created.
-
Once the app is created you will see a window with App details.
Making an API call using Postman
-
Next step is to get the access token. If you're connecting with your developer org, use:- https://login.salesforce.com/services/oauth2/token as the URL to get the access token however, if you're using a sandbox, you can use https://test.salesforce.com/services/oauth2/token as the token URL.
-
Open Postman and setup the call.
Make sure that the x-www-form-urlencoded radio button is selected. Add below five key-value pairs.
Key: username | Value: <your login username for org>
Key : password | Value: < your orgs login password>
Key : grant_type | Value: password
Key : client_id | Value: <consumer key of your salesforce org's connected app>
Key : client_secret | Value: <consumer secret of your salesforce org's connected app>
Note: Note : Key- password: would require login secret token too. -
Once you make the call you will receive an error, Salesforce requires additional parameter for Authentication.
-
To resolve this, go to logged in Salesforce site, under user name go to my settings.
-
On my settings page, from left panel under Personal section select Reset My Security Token.
-
On Reset Token Page click Reset Security Token Button.
-
You will receive security token on your registered Email.
-
Append Security Token with actual user’s password and make the call.
-
Generated access token to connect to sales org will be received in the response.
-
Copy and save the Access Token
Note: Note : Access Token has a validity period , you may have to regenerate access token once API call shows Session Expired error. -
Make a call to salesforce to get different accounts available.
-
Copy your salesforce url from email received and generate request url as:
Baseurl/services/data/version/query?q=SOQL query
-
Under headers tab provide key value pair:
Key: Authorization | value: Bearer {{Access Token}}
-
Click Send and you will receive output .
For more information on queries and REST API calls please refer to REST API Developer Guide.
Making Connection to Salesforce through Evolve
To make connection to Salesforce through Evolve, follow below steps:
-
Login to evolve site, go to administrator application.
-
From left Panel Go to connections.
-
On Connections Page go to Data Sources tab.
-
Click Add, to Add a new Data Connection. Fill in the details (We are using API: baseURL/services/data/v49.0/sobjects/Account/{id} to demonstrate).
Note: Note : Password should be your Actual Password + Security Token as used in above postman example. -
Click Save, to Save the data connection.
Using Created Data connection in a Composer Solution
-
Go to any other app on Evolve site.
-
From left panel go to Solutions. On Solution page, select Forms library and create a new form Solution (using add Solution Button).
-
Go to Form Tab on new Solution and add a Form field name id.
-
Go to solution tab, under Data Connections, add Data Connection and add details.
Follow below steps to build the API URL from the form field.
-
Under API URL, click on three dots on the right side.
-
On the URL Builder page, again click the three dots on right side to add the field value to URL.
-
Click on the Field Value to select the Form Field.
-
Select the form field added on the Forms page and then click on OK button.
-
URL will be created like this:
/services/data/v49.0/sobjects/account/[/my:myFields/my:id]
-
-
Use Output Schema as mentioned below: (as of now we don’t have any feature to get the schema, we analyze the output/input/error and create schema accordingly).
{ "Id": "string", "IsDeleted": "bool", "Name": "string", "BillingStreet": "string", "BillingCity": "string", "BillingAddress": { "city": "string", "state": "string", "street": "string" }, "ShippingStreet": "string", "ShippingCity": "string", "ShippingState": "string" }
-
Once the details are filled, click ok button to add the data connection.
-
Under the solutions Tab, right click on created data connection and select Create form Fields Option.
-
On Field Mapping Dialog, fill in the details.
-
Click Next.
-
On Field Mapping field Dialog, you can edit and make any changes in the field mapping if required, else click Ok.
-
Go to Form Tab on the composer solution, and drag the required fields related to dataconnection on the form.
-
Add a button on the form and configure a webservice to run on the added button click.
-
Add the webservice element on form tab.
-
Select the get service in the dropdown.
-
Select the Invoked By Button checkbox.
-
-
Go to Solution tab → Deploy and launch the solution.
-
On Launched form fill the id you want to fetch data for (id: 0012w00000UWpwPAAT), click added button to run the webservice.
-
Queried data should be displayed on the form.
-
Similarly other operations POST, PUT etc. can be used as per requirement.
For more details see REST API Developer Guide.