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();

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()
|improve this answer|||||
  • Can't you just ApexPages.addMessages(e)? – Adrian Larson Sep 27 '19 at 15:56
  • @AdrianLarson Yeah, I just totally spaced that method. – sfdcfox Sep 27 '19 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.