Can I return a 500 error from an Apex Controller?

PageReference success = new PageReference('http://www.google.com');
  return success;
  return 500 error
  • Can you clarify how you're trying to use this? There may be a different method that works better with controllers.
    – Mike Chale
    Jan 30, 2014 at 13:34

2 Answers 2


The only status codes you're in control of are in @RestResource annotated classes. It is not possible to specify return status codes on Visualforce pages or webservice functions.


Yes, depending on the situation. There is a HttpResponse class, where you can set response code. This should be possible if you're returning a HttpResponse. You don't say exactly how you hope to use, though, so we can't say for certain.

  • The header for this class says to: "Use the HttpResponse class to handle the HTTP response returned by the Http class". I'm asking how to return a 500 response from an Apex Controller. I don't believe the HttpResponse class in intended for this use.
    – ScArcher2
    Jan 29, 2014 at 22:14
  • If your controller's methods can return an HttpResponse (e.g. acting as a web service) it could. It depends on your method's signature.
    – Mike Chale
    Jan 30, 2014 at 13:33

You must log in to answer this question.

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