I'm trying to capture a HttpResponse StatusCode in a @future method so I can then send it to an email to alert a dev of a possible issue and also alert the Salesfroce user of the error. I have found post on how to handle REST errors but not HttpResponse StatusCode. Is there a best practice or are they interchangeable?

1 Answer 1


Probably it would be a better idea to add to the email message both status code and status message. Status code is provided not for human readability but more for identifying the status of the request and to not be dependent on server implementation. Different servers could provide different messages for the same status. So that is why you should better to use both.

  • thank you for your input. I was thinking of using a switch statement over and if then else to shuffle through the different status codes. Are switch statements useful in apex or are they unnecessary extra work?
    – Richard
    Dec 11, 2019 at 21:09
  • It depends what are you going to implement. If you send email to dev it would be enough to send what I wrote above and maybe some additional information about request, like parameters. You may add this if something went wrong. Successful requests are not needed to be emailed, it's overhead. Dec 11, 2019 at 21:14

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.