Unlocking Efficiency in Salesforce with Composite API
In the ever-evolving world of Salesforce integrations, one of the most powerful yet underutilized tools is the Composite API. Part of Salesforce’s REST API suite, Composite API empowers developers to combine multiple API requests into a single HTTP call, drastically reducing the need for repetitive round-trips between client and server.
This feature is a game-changer for performance optimization and plays a critical role in reducing API consumption, especially in high-volume, enterprise-level environments.
🔹 Why Use Composite API?
Composite API is ideal when you want to:
- ✅ Execute multiple operations in one go
Create, update, or delete several records together in a single request. - 🔁 Pass data between requests
For example, create an Account first, then use its ID to create a Contact associated with that Account. - 🔄 Maintain logical flow or dependency between steps
Ideal for workflows where certain operations depend on others being completed first.
🔹 Types of Composite APIs in Salesforce
✅ 1. Composite Request API
- Combine up to 25 sub-requests in one HTTP call.
- Reference IDs from previous sub-requests using @{referenceId.id}.
- Supports all standard HTTP methods — GET, POST, PATCH, DELETE.
📌 Use Case Example:
Create an Account and then immediately create a Contact linked to that new Account, all within a single request.
✅ 2. Composite Batch
- Allows 25 independent sub-requests in one call.
- Unlike Composite Request, there is no dependency between operations.
- Best for bulk operations where the sequence doesn’t matter.
✅ 3. SObject Tree API
- Designed for inserting related records in one go.
- Ideal for parent-child relationships, like Account → Contact → Case.
- Great for syncing hierarchical data during migrations or system integrations.
🔹 Sample JSON for a Composite Request
Here’s a quick example showing how to create an Account and a linked Contact in one call:
json
{
“allOrNone”: true,
“compositeRequest”: [
{
“method”: “POST”,
“url”: “/services/data/v57.0/sobjects/Account”,
“referenceId”: “refAccount”,
“body”: {
“Name”: “Acme Inc”
}
},
{
“method”: “POST”,
“url”: “/services/data/v57.0/sobjects/Contact”,
“referenceId”: “refContact”,
“body”: {
“LastName”: “Smith”,
“AccountId”: “@{refAccount.id}”
}
}
]
}
This example shows how to chain requests — the Contact automatically links to the Account just created.
🔹 Benefits of Using Composite API
- 🔄 Fewer API calls = Better performance
- ⚡ Faster execution due to reduced network overhead
- ✅ Simplified transaction handling with allOrNone flag
- 🔗 Seamless chaining of related logic (especially useful in dynamic, metadata-driven flows)
🔚 Final Thoughts
Salesforce’s Composite API is a powerful feature for developers aiming to streamline integrations, reduce API consumption, and boost performance. Whether you’re managing high-volume data transactions or building dynamic, multi-step automation flows, Composite API is your go-to tool.
Start using it today to supercharge your Salesforce integration!