When making an HTTP callout from Salesforce Apex to a third-party REST API, the callout may fail with a System.CalloutException timeout error. This article explains how to catch the timeout exception in Apex, how to configure a custom timeout value on the HttpRequest object, and the default and maximum timeout values supported by Salesforce.
To handle timeout errors gracefully in Salesforce Apex, wrap the HTTP request execution in a try-catch block that catches System.CalloutException. When a timeout occurs, the system throws a System.CalloutException. Inside the catch block, add your error handling logic, such as retrying the callout, logging the error, or notifying the user.
The pattern is:
You can also log helpful debug information such as the response status code and status message to assist with troubleshooting.
The callout timeout is configurable in Apex using the setTimeout() method on the HttpRequest object. The timeout value is specified in milliseconds.
To set a custom timeout:
Timeout limits:
For example, to set a 30-second timeout, call req.setTimeout(30000) before executing the callout. If your integration requires more time to respond than the default 10 seconds, increase the timeout value up to the maximum of 120 seconds.
If the third-party API consistently exceeds the maximum 120-second timeout, you should consider an asynchronous callout pattern using Salesforce Queueable Apex or a scheduled job.
000387845

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.