Newer Version Available
Improve Performance with the Composite Resource
Use the /tooling/composite
resource to improve the performance of a development tool or app built with Tooling API. This
resource executes a series of Tooling API requests in a single call, minimizing the number of
round trips needed between the client and server. You can use the output of one request as the
input to a subsequent request. The requests’ response bodies and HTTP statuses are returned in
a single response body. The entire request counts as a single call toward your API
limits. Available in API version 40.0 and later.
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.
The following resources support composite.
- All sObject resources (vXX.X/tooling/sobjects/)
- The Query resource (vXX.X/tooling/query/?q=soql)
- URI
- /vXX.X/tooling/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 following composite request body includes five subrequests.
- 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.
1{
2 "allOrNone":false,
3 "compositeRequest":
4 [
5 {
6 "method":"POST",
7 "body":{
8 "Name":"MetadataContainer Unique Name"
9 },
10 “url":"/services/data/v40.0/tooling/sobjects/metadatacontainer/",
11 "referenceId":"metadatacontainer_reference_id"
12 },
13 {
14 "method":"POST",
15 "body":{
16 "contententityid":"<ID of an ApexClass you want to update>" ,
17 "fullname":"ApexClassMemberUniqueFullName",
18 "body":"public class Classtest2test {}",
19 "MetadataContainerId":"@{metadatacontainer_reference_id.id}"
20 },
21 "url":"/services/data/v40.0/tooling/sobjects/apexclassmember/",
22 "referenceId":"apexclassmember_reference_id"
23 },
24 {
25 "method":"POST",
26 "body":{
27 "IsCheckOnly":"false",
28 "MetadataContainerId":"@{metadatacontainer_reference_id.id}"
29 },
30 "url":"/services/data/v40.0/tooling/sobjects/containerasyncrequest/",
31 "referenceId":"containerasyncrequest_reference_id"
32 },
33 {
34 "method":"GET",
35 "url":"/services/data/v40.0/tooling/sobjects/containerasyncrequest/@{containerasyncrequest_reference_id.id}",
36 "referenceId":"containerasyncrequest_GET_reference_id"
37 },
38 {
39 "method":"GET",
40 "url":"/services/data/v40.0/tooling/sobjects/metadatacontainer/@{metadatacontainer_reference_id.id}",
41 "referenceId":"metadatacontainer_GET_reference_id"
42 }
43 ]
44}