Salesforce Composite Connector — Save requests from MuleSoft to Salesforce

Ismeet Kaur
Another Integration Blog
4 min readMar 22, 2023

What happens when you send multiple requests to your Salesforce org? How many requests are too many?

Overview

Salesforce Composite connector enables you to work with the Salesforce Batch and SObject Tree APIs. That means you can send multiple requests at once to Salesforce and use the output of the requests as input to the subsequent requests in that batch.
This is super beneficial when you have complex integrations to Salesforce and need to call the org multiple times in the same API. If the number of requests is high with multiple callouts, it can lead to reaching the maximum limit of requests that Salesforce can handle per day. To check your org’s request limit, refer here.

Authentication Types

Salesforce Composite Connector can use any of the following authentication types:

  • OAuth 2.0
  • OAuth JWT
  • OAuth SAML
  • OAuth username and password

Installing the Salesforce Composite Connector

  • By default, the connector is not a part of the MuleSoft palette. To add this you must “Search in Exchange”. Log in to your Anypoint platform from your Anypoint Studio.
Log into your Anypoint Platform from Anypoint Studio
  • In the search bar, type in composite to search for the connector from the exchange. Once found, click on the connector and click on add and Finish.
Add the connector

Composite Request

We spoke earlier that Composite Requests are a great way to send requests to Salesforce in batches and reuse the output as input to subsequent requests. But how many requests can we bundle up? There is a limit to all the good things in life. Here too, you can send around 25 subrequests in a single call. Subrequests are individual requests inside a composite call.

The response of a composite call is a single request containing the response of each subrequest.

Sample Request Body (ref)
Sample Response Body (ref)

Example of “Execute composite request”

There are many operators available in the Salesforce Composite Connector. Today we will focus on “Execute composite request”. We will particularly learn how we can form the request body for a composite request call. We are creating a very simple flow as shown in the image below.

Step 1:
We are creating a very simple flow as shown in the image below. Our main focus is to create the request body of the composite request. We have a listener where we receive a payload. We will use this payload, divide it up and send multiple requests at once using the composite connector.

Overall Flow for sending a composite request to Salesforce

Step 2:
In the transform message, we will build our request body as a variable or it can be a payload and pass that in the “Execute Composite Request” connector.

Request body consisting 2 requests for Composite call

Key things to remember:

  • Ensure that the output data type is application/json. Application/java can change the data type and run into errors.
  • To create the composite request, it is essential that we create an object with a root element as “compositRequest” which consists of an array of objects. Essentially, each subrequest should be an object on its own.
  • Each subrequest object must contain a method, URL, referenceId, and body.
    Method:
    The method of the request, can be any CRUD operation.
    URL: Always structured “/services/data/v51.0/sobjects/” + “ObjectName”+”externalId”
    ReferenceId: This can be given by the user. This Id allows you to refer to the output of the request in the subsequent request body.
    Body: Consists of the actual request body to be sent to Salesforce. It is an object data type.

Step 3:

Configure the Execute composite request connector. In the request body, we pass the variable we created in step 2.

Execute Composite request configurations

To configure the connector configuration, refer to the image below. We have used the connection as OAuth Username Password.
ConsumerKey = Salesforce consumer key
ConsumerSecret = Salesforce consumer key
Username = Your username to log on to Salesforce org
Password = Your Salesforce org password
SecurityToken: Your security Token
TokenEndpoint: Where we retrieve the OAuth token from “https://test.salesforce.com/services/oauth2/token"

Connector configuration details

Step 5:
Log the results or use the results to continue the integration.

Next Steps

Once you are successful in replicating this simple case scenario, move towards more complex, using outputs as input bodies for the subsequent requests. You can also explore other operators available via the Salesforce Composite Request connector.
For further reference please follow the links, MuleSoft Documentation, and Salesforce Documentation.

--

--

Ismeet Kaur
Another Integration Blog

I want to inspire women to not be afraid and take on tech. I encourage all Women who Mule to stand stronger together.