Salesforce APIs: REST, SOAP, Composite, GraphQL and Apex REST
Which API to use for which job, how to reduce round trips with Composite, when to write a custom Apex REST service, and the API limits architects must plan for.
Simple explanation
| API | Use it for | Notes |
|---|---|---|
| REST API | Most record operations and queries from modern clients | JSON, resource-based; sobjects, query, search |
| Composite resources | Several operations in one round trip | composite (dependent steps with references, up to 25 subrequests), sObject Collections (up to 200 records per call), composite/tree (parent with children), composite/batch |
| GraphQL API | Reading exactly the fields a UI needs across related objects in one query | Efficient for front ends and mobile |
| SOAP API | Legacy or strongly typed enterprise clients (WSDL) | Still supported; also used for some admin operations |
| Bulk API 2.0 | Large volumes asynchronously | See the Bulk API concept |
| Pub/Sub API | Subscribing to and publishing events (gRPC) | See event-driven integration |
Apex REST / SOAP (@RestResource) | A business operation that isn't simple CRUD | Your own contract, validation and transaction control |
| Metadata / Tooling API | Deployments and developer tooling | Not for business data |
Custom Apex REST vs standard APIs: standard APIs are free to maintain and well documented, but expose your data model to the client and push orchestration onto it. A custom Apex REST service gives a stable contract, one transaction and server-side validation. Use it when the client needs a business operation ("submit claim") rather than table access.
Limits to plan for: daily API request allocation per org (based on edition and licences), the concurrent long-running request limit, and per-call limits (records per collection call, payload sizes) β verify current values. Integrations should use Bulk API for volume and Composite to reduce call counts.
Real-world analogy
Standard REST is a self-service warehouse: clients walk the aisles and pick items themselves. Composite is a shopping list handed in at once. A custom Apex REST service is a counter with a clerk: the client asks for "a home office kit" and the clerk assembles the right items, checks stock and charges once.
Worked example
Create an account with two contacts in one call using a composite request with references:
POST /services/data/v66.0/composite
Authorization: Bearer <access token>
Content-Type: application/json
{
"allOrNone": true,
"compositeRequest": [
{ "method": "POST", "url": "/services/data/v66.0/sobjects/Account",
"referenceId": "newAccount", "body": { "Name": "Northwind Traders", "ERP_Id__c": "C-48213" } },
{ "method": "POST", "url": "/services/data/v66.0/sobjects/Contact",
"referenceId": "c1", "body": { "LastName": "Okafor", "AccountId": "@{newAccount.id}" } },
{ "method": "POST", "url": "/services/data/v66.0/sobjects/Contact",
"referenceId": "c2", "body": { "LastName": "Lindqvist", "AccountId": "@{newAccount.id}" } }
]
}
A custom business operation with Apex REST:
@RestResource(urlMapping='/claims/v1/submit')
global with sharing class ClaimSubmissionApi {
global class ClaimRequest { public String policyNumber; public String description; public Date incidentDate; }
global class ClaimResponse { public String claimId; public String status; }
@HttpPost
global static ClaimResponse submit() {
ClaimRequest req = (ClaimRequest) JSON.deserializeStrict(RestContext.request.requestBody.toString(), ClaimRequest.class);
if (String.isBlank(req.policyNumber) || req.incidentDate == null) {
RestContext.response.statusCode = 400;
return null;
}
ClaimResponse res = new ClaimResponse();
res.claimId = ClaimService.submit(req.policyNumber, req.description, req.incidentDate); // one transaction
res.status = 'RECEIVED';
RestContext.response.statusCode = 201;
return res;
}
}
The API version in URLs changes three times a year; pin a tested version in each client β verify the current version.
Diagram
Key points
- REST for most CRUD; Composite and sObject Collections to cut round trips.
- GraphQL for reading exactly what a UI needs.
- Apex REST for business operations with a stable contract and one transaction.
- Bulk API 2.0 for volume; Pub/Sub API for events.
- Plan daily API allocations and concurrent long-running request limits.
- Pin and test API versions per client.
Limits and gotchas
- Chatty integrations (one call per record) exhaust daily API allocations. Use collections, composite or Bulk.
allOrNonesemantics differ between composite resources. Choose deliberately and handle partial failures.- Custom Apex REST runs as the calling user: enforce sharing and user-mode access, and validate input strictly (
deserializeStrict). - Breaking a public Apex REST contract breaks clients. Version the URL (
/v1/,/v2/).
π€ How to say this in an interview
Expect "an external system needs to create orders with lines in Salesforce. Which API?" Answer with Composite (or sObject Collections) for small volumes, a custom Apex REST service if business validation and one transaction matter, and Bulk API 2.0 for large loads, then mention authentication through an External Client App.
Common follow-ups
How do you protect the daily API allocation?
Use bulk and composite calls, cache reference data in middleware, use events instead of polling, monitor API usage per integration user, and set alerts before the allocation is reached.
When would you choose SOAP today?
When an enterprise client already uses typed WSDL-based tooling or a vendor product only supports SOAP. For new integrations REST is the default.