Hey friends,
The Salesforce Composite API is a family of five REST resources that run several operations in one request: composite, composite graph, composite batch, sObject tree and sObject collections. They save round trips, and most of them count as a single API call. The differences that matter are how many subrequests each takes, whether one can use another's output and what happens to the rest when one fails.
Composite is the synchronous option in Salesforce API types, and it's what Salesforce points to for fewer than about 2,000 records, while Bulk API 2.0 takes the bigger loads. It comes up in the Design section of the Salesforce Certified Platform Integration Architect exam, so I've kept every limit tied to a Salesforce page.
What are the five composite resources?
Salesforce's API developer blog post compares them. The record counts below come from that post:
| Resource | What it does | Limits |
|---|---|---|
| Composite | A series of subrequests, where one can use another's output | 25 subrequests, and only 5 of them can be queries or sObject collections. CRUD on up to 1,020 records. allOrNone supported |
| Composite graph | Several independent graphs in one call, each all or nothing | 75 graphs and 500 subrequests per request, across all graphs. sObjects only |
| Composite batch | Independent subrequests, such as a mix of sObject, query, search and Connect calls | 25 subrequests. Each commits on success, and each counts toward API limits |
| sObject tree | A tree of nested parent and child records | 200 records across five sObject types, five levels deep |
| sObject collections | The same action on many records | Writes: 200 records, with allOrNone. Reads: 2,000 records. One call toward API limits |
Everything above counts as one call toward your API limits except composite batch, where each subrequest counts.
How does the Composite resource work?
You POST a compositeRequest to /services/data/vXX.X/composite. Each subrequest has a method, a URL, a body and a referenceId, and later subrequests can use an earlier one's result with @{referenceId.id}. This example from the Composite resource page creates an Account and a Contact under it:
A request can hold up to 25 subrequests, and up to 5 of them can be sObject collections or queries. The subrequests all run in one call, and the response carries each one's status and body.
What does allOrNone do?
It decides what happens when a subrequest fails. Per the Composite request body page, you set it at the top of the request body:
allOrNone: true: the entire composite request is rolled back, and the top-level request still returns HTTP 200 with a response for each subrequest.allOrNone: false: the remaining subrequests that don't depend on the failed one still run. Dependent subrequests don't.
It gets trickier when you nest an sObject collections call inside a composite request, because both can have their own flag. The allOrNone parameters page spells out the four cases:
| Composite flag | Collections flag | Result |
|---|---|---|
| false | false | Nothing rolls back. Records that save stay saved |
| false | true | Only the collections subrequest rolls back |
| true | true | Both roll back |
| true | false | The outer flag wins. The whole request rolls back, and the other subrequest returns PROCESSING_HALTED |
The rule to remember: the outer composite flag, when true, overrides the collection's flag. The collection's own flag defaults to false.
If you learn best by testing yourself, the Platform Integration Architect Cert Lab has quick practice questions on composite and bulk API choices, with every option explained.
When do I need a composite graph?
When one call needs a more complicated set of related records, or you want several independent groups that can succeed or fail on their own. The composite graph page says regular composite requests are limited to 25 subrequests and graphs raise that to 500. Each graph is all or nothing, and one graph failing doesn't affect the others.
Every graph has a graphId. It has to be unique in the request, start with an alphanumeric character, be shorter than 40 characters and not contain a period. Graph nodes only support three kinds of URL: create on sobjects/sObject, row operations on sobjects/sObject/id and row operations by external ID. Here's a small graph:
What is composite batch for?
Independent work. The composite batch page says it runs up to 25 subrequests in order, all as the same user, and the subrequests can't pass information to each other. When one succeeds it commits, and a later failure doesn't undo it. Each subrequest counts against rate limits. Use it to update a record and read something unrelated in one trip. Use composite or a graph if the steps depend on each other.
What are sObject tree and sObject collections?
sObject tree creates nested parent and child records, like an Account with its Contacts, in one request. The sObject tree page lists the limits: 200 records in total across all trees, up to five record types, five levels deep. Records are created in the order you list them, and if one fails the entire request fails. Triggers fire separately for each group of records at the same level, for example all the second-level Contacts.
sObject collections run one action on many records, with the whole request counting as a single API call. The collections page says it's available in API version 42.0 and later. For writes, allOrNone is optional and defaults to false, and for creates you set the type on each record and leave the ID off. Updates need both the ID and the type.
How do I choose between them?
| If you need to... | Use |
|---|---|
| Create or update a few related records and use each result in the next step | Composite |
| Build a larger set of related records, with each group all or nothing | Composite graph |
| Run unrelated operations in one trip | Composite batch |
| Create a parent with its children | sObject tree |
| Insert, update or delete up to 200 of the same kind of record | sObject collections |
| Load or change more than about 2,000 records, with no one waiting | Bulk API 2.0 |
How does Composite API show up on the exam?
As a requirement with a hint in it. "Create an account and its contacts in one transaction" points to composite or sObject tree. "Roll everything back if anything fails" points to allOrNone. "Several related record sets, each independent" points to composite graph. "Fewer calls to stay under API limits" points to any of them over single REST calls. The study plan page has a practice question on it: see the practice questions.
I'll be honest about how I learned this stuff. I loved Focus on Force and used it through 17 Salesforce certifications. Reading the study guide first was slow for me; taking practice tests rapid-fire and studying every wrong answer was fast. So when I built Cert Lab, I built it around that: test yourself quickly, see why each option is right or wrong.
FAQ
What is the Composite API in Salesforce?
A set of REST resources that run multiple operations in one request: composite, composite graph, composite batch, sObject tree and sObject collections.
How many subrequests can a composite request have?
Up to 25, and only 5 of them can be queries or sObject collections. Composite graph raises the limit to 500 across up to 75 graphs.
Does Composite API count as one API call?
Yes for composite, graph, tree and collections. The exception is composite batch, where each subrequest counts toward your limits.
What does allOrNone do in a composite request?
When true, the whole request rolls back if any subrequest fails. When false, subrequests that don't depend on the failed one still run.
What is the difference between composite and composite batch?
Composite subrequests can use each other's results and can roll back together. Composite batch subrequests are independent and commit one by one.
Where should you go next?
- Salesforce Bulk API 2.0 for the large-volume side.
- Salesforce API types for the full comparison.
- Apex trigger best practices since triggers fire on every record you write.
- Platform Integration Architect study plan for the full exam.
Nick Frates, a senior Salesforce developer with 17 certifications, built the Platform Integration Architect Cert Lab at nickfrates.com: rapid-fire practice questions for every exam section, each answer explained.
Cert Lab by Nick Frates
Let the Platform Integration Architect Cert Lab test you to success
Lessons, flashcards, a quiz for each of the six exam sections and full practice exams, every answer explained.
Start the Platform Integration Architect Cert Lab for $9.99 →Not ready to buy? Try a free lesson and see how fast you learn.
Hope this helps!
Best,
Nick


