Newer Version Available

This content describes an older version of this product. View Latest

Composite Request Body

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

Composite Collection Input

The request body contains an allOrNone flag that specifies how to roll back errors and a compositeRequest collection that includes subrequests to execute.
Properties
Name Type Description Required or Optional
allOrNone Boolean

Specifies what to do when an error occurs while processing a subrequest. If the value is true, the entire composite request is rolled back. The top-level request returns HTTP 200 and includes responses for each subrequest.

If the value is false, the remaining subrequests that don’t depend on the failed subrequest are executed. Dependent subrequests aren’t executed.

In either case, the top-level request returns HTTP 200 and includes responses for each subrequest.

Optional
compositeRequest Composite Subrequest[] Collection of subrequests to execute. Required
JSON example
1{
2   "allOrNone" : true,
3   "compositeRequest" : [{
4      Composite Subrequest
5      },{
6      Composite Subrequest
7      },{
8      Composite Subrequest
9   }]
10}

Composite Subrequest

Contains the resource, method, headers, body, and reference ID for the subrequest.
Properties
Name Type Description Required or Optional
body Varies The input body for the subrequest.

The type depends on the request specified in the url property.

Optional
httpHeaders Map<String, String> Request headers and their values to include with the subrequest. You can include any header supported by the requested resource except for the following three headers.
  • Accept
  • Authorization
  • Content-Type
Subrequests inherit these three header values from the top-level request. Don’t specify these headers in a subrequest. If you do, the top-level request fails and returns an HTTP 400 response.
Optional
method String The method to use with the requested resource. Possible values are POST, PUT, PATCH, GET, and DELETE (case-sensitive). For a list of valid methods, refer to the documentation for the requested resource. Required
referenceId String Reference ID that maps to the subrequest’s response and can be used to reference the response in later subrequests. You can reference the referenceId in either the body or URL of a subrequest. Use this syntax to include a reference: @{referenceId.FieldName}.

You can use two operators with the reference ID.

The . operator references a field on a JSON object in the response. For example, let’s say you retrieve an account record’s data in one subrequest and assign the reference ID Account1Data to the output. You can refer to the account’s name in later subrequests like this: @{Account1Data.Name}.

The [] operator indexes a JSON collection in the response. For example, let’s say you request basic account information with the SObject Basic Information resource in one subrequest and assign the reference ID AccountInfo to the output. Part of the response includes a collection of recently created accounts. You can refer to the ID of the first account in the recent items collection like this: @{AccountInfo.recentItems[0].Id}.

You can use each operator recursively as long as it makes sense in the context of the response. For example, to refer to the billing city component of an account’s compound address field: @{NewAccount.BillingAddress.city}.

referenceId is case-sensitive, so pay close attention to the case of the fields you’re referring to.

Required
url String The resource to request.
  • The URL can include any query string parameters that the subrequest supports. The query string must be URL-encoded.
  • You can use parameters to filter response bodies.
  • The URL must start with /services/data/vXX.X/.
Required
JSON examples
1{
2   "method" : "GET",
3   "url" : "/services/data/v38.0/sobjects/Account/describe",
4   "httpHeaders" : { "If-Modified-Since" : "Tue, 31 May 2016 18:00:00 GMT" },    
5   "referenceId" : "AccountInfo"
6}
1{
2   "method" : "POST",
3   "url" : "/services/data/v38.0/sobjects/Account",
4   "referenceId" : "refAccount",
5   "body" : { "Name" : "Sample Account" }
6}
1{
2   "method" : "GET",
3   "url" : "/services/data/v38.0/sobjects/Account/@{refAccount.id}",
4   "referenceId" : "NewAccountFields"
5}
Usage
Because referenceId is case-sensitive, it’s important to note the case of the fields that you’re referring to. The same field can use different cases in different contexts. For example, when you create a record, the ID field appears as id in the response. But when you access a record’s data with the SObject Rows resource, the ID field appears as Id. In the last example subrequest above, the @{refAccount.id} reference is valid because refAccount refers to the response from the POST in the second subrequest. If you use Id instead (mixed case rather than all lowercase), as in @{refAccount.Id}, you get an error when sending the request because the reference ID uses the wrong case.

You can have up to 25 subrequests in a single call. Up to 5 of these subrequests can be query operations, including Query, QueryAll, and “Query More” requests to obtain the next batch of query results.

Note