REST API To Salesforce Sync (Without Mule Connector)

Author: Pankuri Bansal & Nikhil Kumar

This blog shows how you can sync your API to the Salesforce system without any MuleSoft Salesforce connector.

Let’s have a look.

  • For this, firstly, we need a Salesforce Connected App.
What is a Connected App?

Connected apps are frameworks built for Salesforce that enable external applications to integrate with it through APIs and protocols like SAML, OAuth, and OpenID Connect. This helps to create a seamless experience between the two platforms.

Steps:

  • Log in to Salesforce.
  • Click Setup in the upper-right corner.
  • Click on Quick Find (left side search box).
  • Then under Apps click on App Manager.
  • Write the App Name and provide your email address and phone number.
  • Under API (Enable OAuth Settings), click both the check boxes as per the screenshot, then the callback URL is automatically generated.
  • Now come to Scopes, and add both the scopes shown in the screenshot by clicking on add.
  • Click on the Save button.
  • Your Connected APP is created successfully.
  • Now, to connect with external systems or make any other configurations, you need a Client ID and Client Secret.
  • For that click on the Manage Consumer Details Button.
  • Then you will be able to see the details in the below screenshot:
  • Staged Consumer Details are generated only when you click on the generate button highlighted by a red mark in the screenshot.
  • Now open your Anypoint Studio, create a sample Mule application as per the below screenshot.
  • Now, all you need to do is drag and drop the Set Payload component and include all the necessary details in the body.
  • Username: Salesforce login Id.
  • Password:  Salesforce login Password 
  • Grant Type: “password”
  • You can get the Client ID and Client Secret from Salesforce by clicking “Manage Consumer Details” above.
  • Now, configure the Request Component:
  • Method: POST
  • URL for generation of access Token is mainly used to connect with your salesforce/external systems.

https://login.salesforce.com/services/oauth2/token

  • Now Deploy your application and hit the Listener.
  •  Save this access_token in the variable for further use.
  • Following that, create a subFlow utilizing the access_token variable and a flow reference.
  • Request Configurations:
  • Headers: After adding the “Bearer” prefix to your authorization, ensure that there is adequate space otherwise it may cause issues and merge with the access token we have stored in its assigned variable.
{

"Authorization": "Bearer " ++ vars.vaccess_token

}
URL:

Explanation:

(protocol eg: https,http)://(domain name -> click on sf profile you will get)/services/data/(version)/(according to your operation eg: query for GET )

Used In API: https://apiseroinc-a1-dev-ed.develop.my.salesforce.com/services/data/v51.0/query

  • Query Params: Add any query related to the use case you want to retrieve from the Salesforce object.
  • Deploy the application and hit the endpoint.
  • Response:
For Creating Records in Salesforce Object:
  • Now, in order to transform a message, provide a request to pass data into the Salesforce object.
  • When working with connected apps, the standard format for passing requests is in the form of an object instead of an array. This ensures better functionality and compatibility with other services.
Otherwise, you will get the error below:
  • Request Configurations:
  • Deploy the app and trigger.
  • Records are created successfully.

In Salesforce as well,

For Updating Records:
  • Similar to Creating Records, but over here a little bit of difference in request Configurations.
  • The method used: PATCH (PUT Method not supported)
Response:

In Salesforce as well,

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.