Blog

Working with Salesforce sObjects with Composite Connector Part V - Composite Batch

Sivendu SasidharanWritten by Sivendu Sasidharan

In our previous blogs, 'Working with Salesforce sObjects with Composite Connector Part 1' we looked at some common sObject type names in Apex used for standard objects, in 'Working with Salesforce sObjects with Composite Connector Part 2' we looked into Collections. In 'Working with Salesforce sObjects with Composite Connector Part 3' we focused on how to retrieve, update, upsert, and delete records. In 'Working with Salesforce sObjects with Composite Connector Part 4' we focused on Composite requests.

In this blog we will continue to look at working with MuleSoft Salesforce Integration of Salesforce sObjects with Composite Connector, this time focusing on Composite Batch.

  • Executes up to 25 subrequests in a single request.
  • The response bodies and HTTP statuses of the subrequests in the batch are returned in a single response body.
  • Each subrequest counts against rate limits.
  • Subrequests execute serially in their order in the request body
  • Subrequests are independent, and you can’t pass information between them.

Batch Request Body

  • Describes a collection of subrequests to execute with the Batch resource

Batch Collection Input

  • The request body contains a batchRequests collection that includes subrequests to execute.
  • haltOnError - Controls whether Salesforce should stop processing subrequests if a subrequest fails. The default is false. - Optional
  • batchRequests - Collection of subrequests to execute. - Contains the resource, method, and accompanying information for the subrequest.
{
    "batchRequests":
    [
        {
            "method": "PATCH",
            "url": "v34.0/sobjects/account/001D000000K0fXOIAZ",
            "richInput":
            {
                "Name": "NewName"
            }
        },
        {
            "method": "GET",
            "url": "v49.0/sobjects/account/001D000000K0fXOIAZ?fields=Name,BillingPostalCode"
        }
    ]
}

Batch Response Body

  • Describes the result of a Batch request.
  • Collection of subrequest results.
{
    "hasErrors": false,
    "results":
    [
        {
            "statusCode": 204,
            "result": null
        },
        {
            "statusCode": 200,
            "result":
            {
                "attributes":
                {
                    "type": "Account",
                    "url": "/services/data/v49.0/sobjects/Account/001D000000K0fXOIAZ"
                },
                "Name": "NewName",
                "BillingPostalCode": "94105",
                "Id": "001D000000K0fXOIAZ"
            }
        }
    ]
}

Conclusion

The Salesforce Composite Connector from MuleSoft can simplify your code and reduce the processing time by reducing the number of calls to SFDC as multiple records can be created and updated with a single request. Thus reduces network overhead and improves your app’s performance.

References

  • https://developer.salesforce.com/docs/atlas.en-us.apirest.meta/apirest/resources_composite.htm
  • https://dzone.com/articles/salesforce-composite-connector-in-mule-4
  • https://blogs.mulesoft.com/dev/connectivity-dev/salesforce-composite-connector-object-interactions/
  • https://docs.mulesoft.com/salesforce-composite-connector/2.5/