For a feature I am working on, I've been instructed to handle errors by sending emails using the Apex Exception Emails, so when an error occurs, I'm "handling" it by throwing a custom exception.

Now I'd like to see what the email looks like and ensure it would have all the information which might help to diagnose and resolve the problem.

However, no matter what I do to sabotage my solution, I don't receive any emails.

  • Yes, I have checked that my User is listed on the Apex Exception Emails page.
  • Yes, I have checked that my email address is correct on my User record.
  • Yes, I have checked that Deliverability is set to "All email"
  • Yes, I have executed Test Deliverability to ensure I can receive emails (and I do).

Googling this issues seems to suggest that these Apex Exception Emails might lag behind up to 24 hours. This is very annoying from a testing perspective and perhaps someone might feel the issues require more urgent attention.

Is there anything which can be done to adjust and minimize this?

1 Answer 1


The standard mechanism for sending emails from unhandled exceptions is not reliable, see this question: When are unhandled exception emails suppressed and not sent? or Why do I not always get exception emails even though I've set them up?

So, if I were you, I'd query the ApexEmailNotification table directly, and then generate SingleEmailMessages to send in the normal way.

SELECT User.Email, Email FROM ApexEmailNotification

That will work, but the annoying thing is that ApexEmailNotification is not automatically replicated to sandboxes.

  • 3
    My one suggestion here is to try to send the emails using the UserId, not the User.Email, wherever possible (by using SingleEmailMessage.setTargetObjectId) since this avoids using up your daily email limits (emails sent to User objects do not count towards these limits, but emails sent to email addresses obtained from User objects DO).
    – Phil W
    Commented Aug 19, 2020 at 10:51
  • Good point... you must get a lot of error emails! ;o) I was using the email string because it makes the code simpler if you have a mix of users and non-users in the list. But the limit is definitely a consideration worth mentioning
    – Aidan
    Commented Aug 19, 2020 at 12:11

You must log in to answer this question.

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