I am performing a call from Salesforce to the DWH. Rarely, I would exceed the 120000 time limit, but when we do, the user would be presented with a default apex error. I would like to capture that and instead present them with a user friendly error. I am not sure how I can capture that event. How can I say if time limit is exceeded then show an error.

Http http = new Http();
HttpRequest request = new HttpRequest();

1 Answer 1


You can use a try-catch block to check for this condition:

try {
  new http().send(req);
} catch(CalloutException e) {
    new ApexPages.Message(
      'An exception occurred calling the API: '+e.getMessage()
  • Can't you just ApexPages.addMessages(e)?
    – Adrian Larson
    Commented Sep 27, 2019 at 15:56
  • @AdrianLarson Yeah, I just totally spaced that method.
    – sfdcfox
    Commented Sep 27, 2019 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .