Improve Performance with the Composite Resource
For the most current API limit information, see the Salesforce Developer Limits Quick Reference. Contractual limits may also apply, as per your Salesforce contract.
The requests in a composite call are called subrequests. The subrequests are executed in the context of the same user.
In a subrequest’s body, you specify a reference ID that maps to the subrequest’s response. You can then refer to the ID in the url or body fields of later subrequests by using a JavaScript-like reference notation.
You can specify whether an error in a subrequest causes the entire composite request to roll back or just the subrequests that depend on it. You can also specify headers for each subrequest.
- All sObject resources (vXX.X/tooling/sobjects/)
- The Query resource (vXX.X/tooling/query/?q=soql)
- URI
- /vXX.X/composite
- Formats
- JSON
- HTTP method
- GET (lists other available composite resources), POST
- Authentication
- Authorization: Bearer token
- Parameters
- None required
- Request body
- Composite Request Body
- Response body
- Composite Response Body
Example
- The first subrequest creates a MetadataContainer.
- The second subrequest creates an ApexClassMember.
- The third subrequest creates a ContainerAsyncRequest and starts the asynchronous deployment process.
- The fourth subrequest gets the created ContainerAsyncRequest.
- The fifth subrequest gets the created MetadataContainer.
{
"allOrNone":false,
"compositeRequest":
[
{
"method":"POST",
"body":{
"Name":"MetadataContainer Unique Name"
},
“url":"/services/data/v40.0/tooling/sobjects/metadatacontainer/",
"referenceId":"metadatacontainer_reference_id"
},
{
"method":"POST",
"body":{
"contententityid":"<ID of an ApexClass you want to update>" ,
"fullname":"ApexClassMemberUniqueFullName",
"body":"public class Classtest2test {}",
"MetadataContainerId":"@{metadatacontainer_reference_id.id}"
},
"url":"/services/data/v40.0/tooling/sobjects/apexclassmember/",
"referenceId":"apexclassmember_reference_id"
},
{
"method":"POST",
"body":{
"IsCheckOnly":"false",
"MetadataContainerId":"@{metadatacontainer_reference_id.id}"
},
"url":"/services/data/v40.0/tooling/sobjects/containerasyncrequest/",
"referenceId":"containerasyncrequest_reference_id"
},
{
"method":"GET",
"url":"/services/data/v40.0/tooling/sobjects/containerasyncrequest/@{containerasyncrequest_reference_id.id}",
"referenceId":"containerasyncrequest_GET_reference_id"
},
{
"method":"GET",
"url":"/services/data/v40.0/tooling/sobjects/metadatacontainer/@{metadatacontainer_reference_id.id}",
"referenceId":"metadatacontainer_GET_reference_id"
}
]
}