Currently, when an error or exception happens in one of my visual force pages, it redirects users to the 'Authorization Required' page due to the reasons listed here(the Visualforce page you're trying to access has an error): https://help.salesforce.com/articleView?id=000230066&type=1

The user is never shown the exact error, but What I would like to do is email myself when this happens(with the exact error message), but I can't figure out how to accomplish this. Is this possible?


I believe that the Authorization Required error comes from Unauthorized.vfp (by default). You could create your own 'Unauthorized' page, or edit the default with a controller that emails you the contents of Site.ErrorDescription.

  • Unfortunately, by the time the unauthorized page is passed back, the contents of Site.ErrorDescription are: 'Login is required to access this salesforce.com URL. Please contact your administrator if you feel this is an error' Sep 27 '17 at 23:01

Assuming you are using a try-catch block to catch exceptions, you can do several things:

  1. Send yourself an email using Apex messaging
  2. Publish a Platform Event that can be consumed by a trigger or external system

If it is an uncaught exception, you can use Setup | Apex Exception Email to configure sending uncaught exceptions to Users or email distro lists

  • I'm just worried about uncaught exceptions here. The problem is that apex exception emails do not seem to be generated with errors on visual force pages caused by guests Sep 28 '17 at 0:22
  • @HansDonkersloot - is this a sandbox issue? or PROD? My experience is that sandbox will rarely generate an email for apex uncaught exceptions
    – cropredy
    Sep 29 '17 at 0:23

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.