Rest API Salesforce Integration

Creating Salesforce account

Follow below steps to create Salesforce account:

  1. Go to https://developer.salesforce.com/signup

  2. Fill in the details.

  3. Click Sign me up button, you will receive an email for verification and password setup.

  4. Setup Password and security question and login to Salesforce.

  5. 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:

  1. Go to Setup icon (on top right).

  2. Once on the setup window expands, in the left panel under Build Section go to CreateApps.

  3. On the App Window, under Connected Apps section select New to register a new Connected App.

  4. On register New Connected App window, fill in the required fields.

  5. 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.)

  6. Once the details are filled, click Save. Continue on the next window and wait for the App to be created.

  7. Once the app is created you will see a window with App details.

Note: Note : Consumer Key and Consumer Secret will be used to get access token and make API calls to the Salesforce.

Making an API call using Postman

  1. 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.

  2. 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.
  3. Once you make the call you will receive an error, Salesforce requires additional parameter for Authentication.

  4. To resolve this, go to logged in Salesforce site, under user name go to my settings.

  5. On my settings page, from left panel under Personal section select Reset My Security Token.

  6. On Reset Token Page click Reset Security Token Button.

  7. You will receive security token on your registered Email.

  8. Append Security Token with actual user’s password and make the call.

  9. Generated access token to connect to sales org will be received in the response.

  10. 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.
  11. Make a call to salesforce to get different accounts available.

  12. Copy your salesforce url from email received and generate request url as:

    Baseurl/services/data/version/query?q=SOQL query

  13. Under headers tab provide key value pair:

    Key: Authorization | value: Bearer {{Access Token}}

  14. 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:

  1. Login to evolve site, go to administrator application.

  2. From left Panel Go to connections.

  3. On Connections Page go to Data Sources tab.

  4. 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.
  5. Click Save, to Save the data connection.

Using Created Data connection in a Composer Solution

  1. Go to any other app on Evolve site.

  2. From left panel go to Solutions. On Solution page, select Forms library and create a new form Solution (using add Solution Button).

  3. Go to Form Tab on new Solution and add a Form field name id.

  4. 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.

    1. Under API URL, click on three dots on the right side.

    2. On the URL Builder page, again click the three dots on right side to add the field value to URL.

    3. Click on the Field Value to select the Form Field.

    4. Select the form field added on the Forms page and then click on OK button.

    5. URL will be created like this:

      /services/data/v49.0/sobjects/account/[/my:myFields/my:id]

  5. 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"
    }
    
  6. Once the details are filled, click ok button to add the data connection.

  7. Under the solutions Tab, right click on created data connection and select Create form Fields Option.

  8. On Field Mapping Dialog, fill in the details.

  9. Click Next.

  10. On Field Mapping field Dialog, you can edit and make any changes in the field mapping if required, else click Ok.

  11. Go to Form Tab on the composer solution, and drag the required fields related to dataconnection on the form.

  12. 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.

  13. Go to Solution tab → Deploy and launch the solution.

  14. On Launched form fill the id you want to fetch data for (id: 0012w00000UWpwPAAT), click added button to run the webservice.

  15. Queried data should be displayed on the form.

  16. Similarly other operations POST, PUT etc. can be used as per requirement.

For more details see REST API Developer Guide.