In this article, we will give a brief overview of MuleSoft’s Salesforce Composite Connector and the benefits of using it instead of using the traditional approach for implementation.
This connector uses the following salesforce REST API composite resources:
- Composite – executes sequentially several requests in a single call. The response from one request can be used as an input in the subsequent call.
- Batch – allows up to 25 subrequests to be executed in a single request. Each subrequest executes independently and information can’t be shared between the calls.
- SObject Tree – creates one or more sObject trees with root records of the specified type. An sObject tree is a collection of nested, parent-child records with a single root record.
- SObject Collections – reduces round-trip between the client and the server. It allows up to 200 records to be created, updated, retrieved, or deleted with fewer round-trips. We can determine if the entire request should be rolled back in case of an error.
In order to see the differences between the traditional approach and the use of a salesforce composite connector, we are going to create simple flows, using both approaches.
We will create 2 accounts and we will create contacts for both. For the second account, we will also create child accounts.
How will our flow look if we are not using the composite connector?
If we implement the requirement using the classic approach, our flow will look as below:
As we can see from the image, we should make 3 calls to salesforce to insert our records. Additionally, before each call, we need to prepare the request separately.
Sample Request for testing the flow.
Our response can be found here.
How will our flow look if we are using the composite connector?
First, we are going to add the Salesforce Composite Connector in the Mule Palette:
1. In the Mule Palette view, click (X) Search in Exchange
2. In the search field type composite
3. Select the connector’s name in the Available modules section
4. Click the Add button
5. Click the Finish button
Now, when we have the connector listed in our Mule Pallete, we can create our application.
As we can see from the global element properties, the following fields should be populated for the OAuth with Username and Password Configuration:
1. Consumer Key – for the Salesforce connected app
2. Consumer Secret – for the connector to access Salesforce
5. Security Token
The Consumer Key and Secret can be obtained once we create a connected app in Salesforce:
1. Navigate to Setup
2. Go to App Manager (Under PLATFORM TOOLS or search it from the Quick Find box)
3. Click on the New Connected App button
4. Fill the required fields:
– Connected App Name (the API Name will be automatically added)
– Contact Email
5. Enable OAuth Settings and fill the
– Add all supported OAuth scopes to Selected OAuth Scopes.
6. Click the Save button.
After the connected app is created, the Consumer Key can be found under API (Enable OAuth Settings) section. To see the Consumer Secret, we should click the Click to reveal the link.
The same scenario using the Create SObject Tree can be achieved in a single call to salesforce:
Create SObject Tree – is used for creating one or more sObject trees having root records of the specified type. An sObject tree is a collection of nested, parent-child records with a single root record.
In the request, we should provide hierarchies, the required, and the optional field values, the type, and a reference ID of each record.
If successful, the response will contain the IDs of the created records. In case of error, while creating a record, the entire request will fail and the response will have only the reference ID of the record that caused the error and the error information.
The request can contain the following:
- Up to a total of 200 records across all trees
- Up to five records of different types
- SObject trees up to five levels deep
- Because an sObject tree can contain a single record, you can use this resource to create up to 200 unrelated records of the same type.
Our Request can be found here.
We will transform the input message in the following format.
The call was successful, so we have response with six records created with the parent-child relationships specified in the request.
You can see the configuration xml containing both flows here.
If any error occurs when creating a record, none of the records from the requests will be processed. The hasErrors field will be set to true, with an array of records that failed. Also, the reference ID that was provided in the request for the specific record and error details will be returned as part of the response.
As we can see from the examples above, the Salesforce Composite Connector from MuleSoft can reduce the processing time and the number of API calls to SFDC. It can also simplify our flows because multiple records can be created and updated in a single request, dependent requests can be executed in a single API call and it has the ability collection to create nested parent-child records.
Latest MuleSoft Articles
- An external API for custom alerts creation, automatic application restarting, and Jira ticket creation (Mule 4)
- MuleSoft Automation Process of Handling Exception and Creating Tickets using JIRA
- Using Digital Solutions to Enhance Healthcare Part 2 – Healthcare Integration in Mule 4
- Deliver Business Value Faster by Using Accelerators
- How to Accumulate and Modify Values into Variable Using Mule 4 and DataWeave 2?