Sub topic 4
Limits that shape integration design
This chapter assumes you know Salesforce objects and records, can read Apex, and understand REST and JSON. Limits are the main reason an integration that works in a sandbox fails in production. They also drive the choice between native tools and middleware.
Two families of limits
Salesforce enforces two kinds of limits. Mixing them up is a common error.
- API limits cap how many requests an external system can make into Salesforce.
- Governor limits cap what a single Apex transaction can consume, including callouts made out of Salesforce.
| Limit | Typical value | Why it matters |
|---|---|---|
| Daily API requests | Depends on edition and licenses | Many polling clients can use up the quota |
| Concurrent long-running API requests | 25 requests over 20 seconds in production | Slow downstream work blocks other callers |
| Callouts per Apex transaction | 100 | Looping over records and calling out per record fails fast |
| Callout timeout | 10 seconds default, 120 seconds maximum | The remote system must answer quickly |
| Callout response size | 6 MB synchronous, 12 MB asynchronous (heap-bound) | Large payloads need paging |
| Platform Event publishing and delivery | Allocations vary by edition | High-volume event streams can hit them |
Treat these values as examples. Check the current Salesforce limits documentation for your org before you design.
How the limits shape design
Consider an order sync. A trigger fires for each updated Order, and each firing makes a callout to the ERP. Updating 200 records in one batch runs the trigger once for the whole batch. If the code calls out once per record, it makes 200 callouts and the transaction fails at the 101st.
The fix is to send one request for the whole batch, or to hand the work to asynchronous Apex.
public class OrderSync {
@future(callout=true)
public static void sendOrders(Set<Id> orderIds) {
List<Order> orders = [SELECT Id, OrderNumber, Status FROM Order WHERE Id IN :orderIds];
List<Map<String, Object>> payload = new List<Map<String, Object>>();
for (Order o : orders) {
payload.add(new Map<String, Object>{
'orderNumber' => o.OrderNumber,
'status' => o.Status
});
}
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:ERP_Credential/orders/bulk');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setBody(JSON.serialize(payload));
HttpResponse res = new Http().send(req);
if (res.getStatusCode() != 200) {
System.debug('ERP rejected the batch: ' + res.getStatus());
}
}
}This sends one callout for up to 200 records. It stays inside the callout limit, and the @future method keeps the user's save from waiting on the ERP.
The code still has gaps. It does not retry and it has no dead-letter store. A failed call is only logged. A failed batch is lost unless you build your own retry, which is the point where teams start to consider middleware.
Where limits push you toward middleware
Limits favor middleware in these situations:
- Many systems poll Salesforce, which burns the daily API quota. Middleware can read once and fan out.
- Payloads are large or need transformation that exceeds heap or CPU time limits in Apex.
- Retries, queuing, and replay are needed. Apex has no built-in durable retry queue.
- Throughput is bursty. A queue absorbs spikes that would otherwise breach concurrency limits.
Limits do not always mean middleware. Bulk API, batching, Platform Events, and Change Data Capture handle many high-volume cases natively.
Common errors
- Placing a callout inside a loop.
- Making a callout after an uncommitted DML statement in the same transaction. Salesforce throws a "You have uncommitted work pending" error.
- Ignoring the default 10-second timeout and letting a slow ERP stall users.
- Counting only your own API calls and forgetting other connected apps that share the daily quota.
Exercise
An Apex trigger calls an external pricing service once per Opportunity. A data load of 500 Opportunities fails. Name the limit that causes this and give two ways to fix it without middleware.
Show answer
The limit is 100 callouts per Apex transaction. Fixes: send one bulk request per batch of records instead of one per record, or move the callouts to asynchronous Apex such as Queueable, splitting the records into chunks that each stay under the callout limit.
Exercise
Five external systems each poll Salesforce every minute for changed Accounts, and the org is close to its daily API limit. Which pattern reduces API use, and does it need middleware?
Show answer
Replace polling with publish-subscribe. Change Data Capture or Platform Events push changes out, so consumers no longer poll. This can be done natively, though middleware can help if the five systems need different formats or delivery guarantees.