Salesforce Org

Integration of Two Salesforce Org Using REST API - The Complete Guide

What is Integration in Salesforce?

Salesforce integration is the process of incorporating the data and functionality of Salesforce with another operation to give druggies a single unified experience. It allows you to give your platoon an ideal blend of features pertaining to both platforms. 

The integration connects two or more systems together so that if one system calls for anything it can callout or request to another system and in return other system gives a response to the request. 

Advertisement

Integration is widely used in Salesforce like Org to PayPal integration. 

How Can We Callout from One System to Another?

We can do this by using two methods:

  1. REST API
  2. SOAP

In this blog, we are going to show the integration of two-Salesforce org using REST API.

We are going to integrate Salesforce Org A with Salesforce Org B. To achieve this, we have to follow some steps. These steps are as follows:

Step 1: Create two separate Developer orgs Org A and Org B.

Step 2: We have to create a “Connected App” in Org B.

Step 3: We have to create an “Auth. Provider” in Org A.

Step 4: Last step is we have to create “Name Credential” in Org A.

dont miss out iconDon't forget to check out: Unboxing Salesforce Knowledge Rest APIs

Creation of Connected App in Org B

Connected apps are a framework that enables the external app to integrate with Salesforce via APIs. Therefore, we set up a connected app in Org B.

Please follow the configuration below to set up your Connected App:

Navigate to Setup >> App Manager >> New Connected App

Notes:-

  1. Here in Contact Email always enter your own Email Id so that in case of any error or success you can receive an email alert.
  2. Note down your Consumer Key and Secret it will be used in Auth. Provider Step.
  3. Here, Callback URL Value will be taken from Auth. Provider

Creation of Auth. Provider in Org A

Before creating Named Credentials, we need to set up an Auth. Provider in org A. Follows the following steps for creating an Auth. Provider.

  • Navigate to Setup -> Auth. Providers.
  • Click on the new Button.
  • Select “Salesforce” as the Provider Type
  • Provide a Name for Auth. Provider.
  • Provide “Consumer Key” and “Consumer Secret” from the previous step.
  • In “Default Scope”, enter the value as “refresh_token full”.

Then Save.

Creation of Name Credential in Org A

Now we have all the things to set up Named credentials in New Salesforce org. Use the following steps to create Named credentials.

    • Navigate to Setup -> Named Credentials.
    • Click on the new Button.
    • Provide a label.
    • In URL, Provide the Salesforce instance URL of New Salesforce org (Or your org url)
    • Select “Named Principal” in Identity Type.
    • Select “OAuth 2.0” in the Authentication Protocol.
    • Select the Auth. The provider we have created in the previous step in Authentication Provider.
    • Check the “Allow Merge Fields in HTTP Body” checkbox. (This is important to add the request body to the API callout)

dont miss out iconCheck out an amazing Salesforce video tutorial here: Salesforce Rest API | Http Methods | Salesforce Integration

Finally, Save.

Note: In URL Field Mention your Org B Domain which will work as your Endpoint.

Apex Code to Connect with Org B Using Name Credentials:

Http http = new Http ();
HttpRequest request = new HttpRequest();
request.setEndpoint('Callout:SFDCB/services/apexrest/Cases');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
HttpResponse response = http.send(request);

Responses

Popular Salesforce Blogs