INTEGRATION

Salesforce integration is the process of linking Salesforce with external systems, applications, or platforms to facilitate data exchange and optimize business workflows. It helps organizations centralize their data, enhance operational efficiency, and ensure a smooth experience across various tools and technologies.

There are two types of integration in salesforce,

  • Inbound Integration: Use when Salesforce is the primary system for receiving data or operations.
  • Outbound Integration: Use when Salesforce needs to initiate communication with external systems.

In this blog, we will explore inbound integration using Salesforce’s standard REST API.

Inbound Integration

The process where external systems send request or data to Salesforce. Salesforce acts as the receiver of instructions or data, allowing it to process the request from external system and perform actions like querying, creating, updating, deleting records, or returning expected results.

You would use inbound integration when:

  • The external system needs to interact with Salesforce. For example – Creating an order, sending order details, updating customer records, syncing inventory, etc.
  • You want to expose Salesforce objects or custom functionality as RESTful web services for external systems.
  • Salesforce acts as the backend system for a client application, mobile application or website.
  • Real-time data exchange between Salesforce and an external system is crucial in certain scenarios. For instance, we utilized this inbound integration to receive payment confirmations from a payment gateway like Razorpay for one of our clients.
  • Custom business logic in Salesforce needs to be triggered by an external system.

Standard REST API

Salesforce provides standard REST APIs to interact with records and metadata. You should use Salesforce’s Standard REST API if basic record CRUD operations are required such as

  • Creating a Lead record.
  • Querying a Case record.
  • Update a Contact record.
  • Deleting an account record.

Use Case:

  • When the required functionality is supported by Salesforce’s out-of-the-box REST endpoints.
  • When minimal customization is required.

Salesforce provides standard REST API endpoints that can handle the HTTP methods such as GET, POST, PATCH and DELETE. Here are the examples for each HTTP method, assuming Postman as an external system to interact with Salesforce’s REST API.

  1. Login to salesforce and reset the security token from salesforce as shown below. You will get an email that is registered to the respective salesforce account.

View Profile —-> Settings —-> Reset My Security Token

2. Create an user in salesforce for the external system, let them reset the password.
3. Create a connected app in salesforce to get the Consumer Key (client Id), Consumer Secret (client secret) that is to be used in postman (external system).

Setup —-> Quick Find —-> App Manager —-> New Connected App

  1.  

4. Open Postman and create an account.
5. Create a new Collection (e.g., Integration).
6. Add a new http POST request to the collection.
7. Use the POST /services/oauth2/token endpoint with the following parameters in the body:

    • grant_type: password
    • client_id: < Consumer Key as in above screenshot>
    • client_secret: < Consumer Secret as in above screenshot >
    • username: <Salesforce Username>
    • password: <Salesforce Password + Security Token>

8. Save the returned access_token and token_type from the response body. If the session got expired or invalid then get the new access_token.

9. URL: The URL will be of the form: https://.salesforce.com/services/data/vXX.X

Here,

  • Replace with your Salesforce instance.
  • Replace XX.X with the desired API version.

10.  ENDPOINT URL: Here we need to paste the client id, secret key, username and password from connected app

https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=&client_secret=&username=&password=

11. Fill the client Id and client secret in the above URL and paste it in endpoint of postman.

12. Click on send to get the bearer token as shown below.

EXAMPLE -1: GET METHOD
Get the details of a Account by passing ID in the URL.
1. METHOD: Get
2. End point URL:
https://[your_instance_url].salesforce.com/services/data/v54.0/sobjects/Account/a0LJ400000********
Here,
• https://[your_instance_url].salesforce.com is the instance URL,
• We must include data/version/sobjects /OBJECT_NAME/ID in the URL, addition to this instance URL to get the details of a particular record.
• Here we are getting the account details, so subject is Account and copy the ID of an Account in salesforce.
• Version is 54.0. So we need to give v54.0 in the url.
3. HEADER: Give the authorisation and bearer token value.
Here, as shown below, authorisation will be token-type whitespace access-token
Authorisation:
Bearer***************B7k7
4. Click on SEND.
5. Check the status if it is 200 OK, then it will display the details of the account in the response body.
6. Check the details of the account in the response body as shown below.

OUTPUT: In postman

EXAMPLE 2: Create an Account record
1. METHOD : CREATE
2. End point URL: https://[Your_instance_Url].salesforce.com/services/data/v54.0/sobjects/Account
3. HEADER is same as above example.
Authorisation: Bearer***************B7k7
4. BODY:
For REST API we can use XML or JSON Body for creating a record. In this example we are using XML to create an account record.

<Account>
<name>Alena</name>
<AccountNumber>123456</AccountNumber>
<AnnualRevenue>7000000</AnnualRevenue>
<NumberOfEmployees>230</NumberOfEmployees>
</Account>

5. Click on SEND.
6. Check the status if it is 201 Created, the request has been fulfilled and resulted in a new resource being created, then it will display the Id of the newly created record in the response body.
7. Check the details of the account in the response body as shown below.
8. New account is created, check it in salesforce org using the ID.

OUTPUT: In postman

EXAMPLE 3: Create School record
1. METHOD : CREATE
2. End point URL: https://[Your_instance_Url].salesforce.com/services/data/v54.0/sobjects/School__c
3. HEADER is same as above example.
Authorisation: Bearer***************B7k7
4. BODY:
For REST API we can use XML or JSON Body for creating a record. In this example we are using JSON to create the school record.
5. JSON:
{
“Name” : “RMT School”,
“School_Email__c” : “Rmtoff@gmail.com”,
“School_phone__c” : “1878787878”,
“Fees__c” : “90000”
}
6. Click on SEND.
7. Check the status if it is 201 CREATED, then it will display the Id of the newly created record in the response body.
8. Check the details of the school in the response body as shown below.
9. School record is created, check it in salesforce org using the ID.

NOTE: We can use any standard or custom object in salesforce for executing standard REST API methods. We have created the custom object School __c and used in this scenario.

OUTPUT: In postman

EXAMPLE 4: Update Student record

  1. METHOD : PATCH
  2. End point URL : https://[Your_instance_Url].salesforce.com/services/data/v54.0/sobjects/Student__c/a0LJ400000********
  3. HEADER is same as above example.
    Authorisation: Bearer***************B7k7
  4. BODY:

    For REST API we can use XML or JSON Body for creating a record. In this example we are using JSON to Update the email and phone number of a student record.

  5. JSON:

    {

    “Phone_Number__c” : “1234567890”,

    “Email__c” : “patch001@gmail.com”

    }

  6. Click on SEND.
  7. If successful, no content (204 No Content) is returned in the response body.
  8. Check the details of the student as shown below.
  9. Student record is updated, check it in salesforce org using the ID.

NOTE: We can use any standard or custom object in salesforce for executing standard REST API methods. We have created the custom object Student__c and used in this scenario.

OUTPUT: In postman

EXAMPLE 5: Delete Student record

  1. METHOD : DELETE
  2. End point URL : https://[Your_instance_Url].salesforce.com/services/data/v54.0/sobjects/ Student__c/a0MJ400000********?=
  3. HEADER is same as above example.
    Authorisation: Bearer***************B7k7
  4. Click on SEND.
  5. If successful, no content (204 No Content) is returned in the response body.
  6. The student record is deleted in salesforce org.

NOTE: We can use any standard or custom object in salesforce for executing standard REST API methods. We have created the custom object Student__c  and used in this scenario.

Are you planning to extend your team with CRM Experts?