Blog

Working with Salesforce sObjects with Composite Connector Part IV - Composite Request

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 this blog we will continue to look at working with with MuleSoft Salesforce Integration of Salesforce sObjects with Composite Connector, this time focusing on Composite requests. Composite requests can execute a series of REST API requests in a single call. This allows multiple requests to be packed in a single request which can significantly reduce the number of Salesforce Platform API usage.

Composite requests can execute a series of REST API requests in a single call. This allows multiple requests to be packed in a single request which can significantly reduce the number of Salesforce Platform API usage.

Composite request allows output of one request as the input to a subsequent request and the entire series of requests counts as a single call toward your API limits.

The request in a composite call is called subrequests and In the subrequest's body we can specify a reference ID that maps to a subsequent response. This ID we can refer to in the url or body of later subrequest.

Composite Request Body

Describes a collection of subrequests to execute with the Composite resource.

Composite Collection Input

  • allOrNone:

    • Optional
    • Specifies what need to be done when an error occurs while processing a subrequest
  • collateSubrequest:

    • Controls whether API collates(combines) unrelated subrequest to bulkify them(true) or not(false)
    • Subrequest that contains valid Http headers are not collated
    • Conditions to collate
    • The HTTP methods are the same.
    • The API versions of the resources are the same.
    • The parents of the resources are /sobjects resources.
    • No more than five sObjects resources are present across a grouping of subrequests.
  • compositeRequest:

    • Collection of subrequests to execute
    • Contains the resource, method, headers, body and reference ID for the subrequest
{
    "allOrNone": false,
    "collateSubrequests": null,
    "compositeRequest":
    [
        {
            "method": "POST",
            "url": "/services/data/v49.0/sobjects/Account",
            "referenceId": "refAccount",
            "body":
            {
                "Name": "Sample Account"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v49.0/sobjects/Contact",
            "referenceId": "refContact",
            "body":
            {
                "FirstName": "Maria",
                "LastName": "Alex",
                "AccountId": "@{refAccount.id}"
            }
        }
    ]
}

Composite Response Body

  • Collection of subsequent results
  • Composite Subrequest result will have body, httpHeaders, httpStatusCode, referenceID
{
    "compositeResponse":
    [
        {
            "body":
            {
                "id": "0012x00000ELiJuAAL",
                "success": true,
                "errors":
                []
            },
            "httpHeaders":
            {
                "Location": "/services/data/v49.0/sobjects/Account/0012x00000ELiJuAAL"
            },
            "httpStatusCode": 201,
            "referenceId": "refAccount"
        },
        {
            "body":
            {
                "id": "0032x00000AKPXAAA5",
                "success": true,
                "errors":
                []
            },
            "httpHeaders":
            {
                "Location": "/services/data/v49.0/sobjects/Contact/0032x00000AKPXAAA5"
            },
            "httpStatusCode": 201,
            "referenceId": "refContact"
        }
    ]
}