The following limits and limitations apply when Apex code makes a callout to an
HTTP request or a web services call. The web services call can be a SOAP API call or any external web
services call.
- A single Apex transaction
can make a maximum of 100 callouts to an
HTTP request or an API
call.
- You can make up to 20 concurrent
callouts to endpoints outside of your Salesforce org’s domain. You can
make unlimited concurrent
callouts to internal endpoints.
- The default timeout is 10 seconds. A custom timeout can be defined for each callout. The
minimum is 1 millisecond and the maximum is 120,000
milliseconds. See the examples in the next section for how to set custom timeouts for
Web services or HTTP callouts.
- The maximum cumulative timeout for callouts by a single Apex transaction is 120 seconds. This time is
additive across all callouts invoked by the Apex transaction.
- You can’t make a callout when there are pending operations in the same transaction.
Things that result in pending operations are DML statements, asynchronous Apex (such as future methods
and batch Apex jobs),
scheduled Apex, or sending
email. You can make callouts before performing these types of operations.
- Pending operations can occur before mock callouts in the same transaction. See Performing DML Operations and Mock Callouts for WSDL-based callouts or Performing DML Operations and Mock Callouts for HTTP callouts.
- When the header Expect: 100-Continue is added to a
callout request, a timeout occurs if a HTTP/1.1 100
Continue response isn’t returned by the external server.
Setting Callout Timeouts
The following example sets a custom timeout for Web services
callouts. The example works with the sample WSDL file and the generated
DocSamplePort class described in
Generated WSDL2Apex Code. Set the timeout value in milliseconds by assigning
a value to the special
timeout_x variable on the stub.
docSample.DocSamplePort stub = new docSample.DocSamplePort();
stub.timeout_x = 2000;
The following is an example of setting a custom
timeout for HTTP callouts:
HttpRequest req = new HttpRequest();
req.setTimeout(2000);