Sub topic 2
Reading the Salesforce Composite Response
Assume you know HTTP methods, status codes, JSON, Salesforce record IDs, and sObject endpoints. A composite request has one outer HTTP response and one result for each subrequest. Always inspect both levels.
Reading `compositeResponse`
The outer status code shows whether Salesforce accepted the composite call. It does not guarantee that every subrequest succeeded. Each item in compositeResponse includes its referenceId, httpStatusCode, and either a body or error details.
{
"compositeResponse": [
{
"body": { "id": "001...", "success": true },
"httpHeaders": { "Location": "/services/data/v60.0/sobjects/Account/001..." },
"httpStatusCode": 201,
"referenceId": "newAccount"
},
{
"body": [
{ "errorCode": "REQUIRED_FIELD_MISSING", "message": "Required fields are missing: [LastName]" }
],
"httpHeaders": {},
"httpStatusCode": 400,
"referenceId": "newContact"
}
]
}A client should iterate over every result and handle status codes separately. Do not treat a successful outer 200 as proof that all operations succeeded.
> callout note > Log the referenceId, status code, and error body. These values identify which operation failed without relying on array position.
Rollback control with `allOrNone`
allOrNone controls transaction behavior for a Composite request:
falseis the default. Successful subrequests can commit even when another fails.truerolls back the completed subrequests if any subrequest fails.
Rollback does not remove the need to inspect each response. Your client still needs to report the original error and distinguish it from operations that were not committed.
Partial failure and halted subrequests
With allOrNone: false, independent subrequests can continue after an error. A subrequest that references a failed result cannot run successfully. Salesforce marks dependent work as halted or returns a reference-related error. A Composite Batch request has a separate haltOnError option: when true, Salesforce stops processing later batch items after an error. These controls are different from allOrNone.
Limits and constraints
A Composite request supports up to 25 subrequests. At most five can be query, queryAll, or queryMore operations. Every subrequest counts toward the API call’s processing and resource limits. Keep requests small enough to debug, and avoid long dependency chains.
Exercise
If the outer response is successful but one item has HTTP 400, should the whole operation be treated as successful?
Show answer
No. Inspect every compositeResponse item and handle the failed subrequest.