What governor limits and execution constraints govern remote HTTP callouts originating from Apex code?
Answer
Basics: A callout is an HTTP (or SOAP) request from Apex to an outside endpoint using Http, HttpRequest, HttpResponse. Salesforce protects its multitenant platform by limiting how many calls you make, how long they take and where they may run. The endpoint must be authorized through a Named Credential or a Remote Site Setting.
How it works:
- Count: 100 callouts per transaction (sync and async).
- Time: each callout defaults to 10 seconds (
setTimeoutin milliseconds, up to 120000); the total time of all callouts in a transaction cannot exceed 120 seconds. - Size: request and response bodies live in heap (6 MB sync, 12 MB async), so large payloads fail first on heap.
- CPU: waiting time for the remote service does not count toward the 10,000 ms CPU limit, but parsing does.
Advanced / deep dive: Context rules matter as much as numbers:
- No callout after uncommitted DML in the same transaction (error: "You have uncommitted work pending").
- No synchronous callout directly in a trigger, and none from
Schedulable.executedirectly; hand off to@future(callout=true)or Queueable withDatabase.AllowsCallouts. - Batch Apex requires
implements Database.AllowsCallouts; eachexecuteis its own transaction with its own 100-callout budget, which is how you scale. - Concurrency: when 10 or more synchronous requests from the org run longer than 5 seconds at the same time, further requests can fail with a concurrent request limit error.
Continuation(for LWC/Aura/Visualforce) avoids this and allows up to 3 callouts per continuation with a 120-second timeout.