Sub topic 3
Bulk Operations with Salesforce Composite Resources
Assume you know HTTP methods, JSON, Salesforce record IDs, and OAuth authentication. These resources all use the REST API, but they optimize different kinds of work.
Bulk operations with sObject Collections
The sObject Collections resource processes up to 200 records of one object type in one request. Use /services/data/v60.0/composite/sobjects for create, update, upsert, or delete operations.
{
"allOrNone": false,
"records": [
{ "attributes": { "type": "Account" }, "Name": "Northwind" },
{ "attributes": { "type": "Account" }, "Name": "Contoso" }
]
}With allOrNone: false, valid records can succeed while invalid records return individual errors. Set it to true when the entire collection must succeed together.
Independent subrequests with Composite Batch
Composite Batch sends up to 25 unrelated REST subrequests to /composite/batch. Each subrequest is independent. It cannot reference another subrequest's result, so use it for parallel work such as describing objects or updating unrelated records.
Set haltOnError to control whether Salesforce stops processing after the first failure.
{
"haltOnError": false,
"batchRequests": [
{
"method": "GET",
"url": "v60.0/sobjects/Account/describe"
},
{
"method": "POST",
"url": "v60.0/sobjects/Account",
"richInput": { "Name": "Batch Account" }
}
]
}Creating record hierarchies with sObject Tree
sObject Tree creates related records in one request. It fits a known hierarchy, such as an Account with Contacts. The request uses nested child relationship names, rather than reference substitutions between separate requests. It supports up to 200 records in the tree.
Composite Graph for larger transactional units
Composite Graph extends dependency-based requests to larger workloads. A graph contains composite subrequests, so later operations can use earlier results such as @{acct.id}. Multiple graphs can share one HTTP call while remaining independent transaction units.
flowchart TD
A[Choose record operation] --> B{Related hierarchy?}
B -->|Yes| C[sObject Tree]
B -->|No| D{Need dependencies?}
D -->|Yes| E[Composite or Composite Graph]
D -->|No| F{Same object collection?}
F -->|Yes| G[sObject Collections]
F -->|No| H[Composite Batch]Choosing the right composite resource
| Need | Resource |
|---|---|
| Up to 200 records of one object | sObject Collections |
| Up to 25 independent REST calls | Composite Batch |
| Nested parent-child creation | sObject Tree |
| Dependent work across larger graphs | Composite Graph |
| A small dependent sequence | Composite |
Exercise
Which resource fits 100 Account records that do not depend on one another?
Show answer
sObject Collections, with allOrNone chosen according to the required rollback behavior.