Not Receiving Unhandled Exceptions Emails

I had have a very minimal code to throw null pointer exception intentionally. The reason was we’re not receiving exception emails. We even reached out to support(You know how it can be painful process).

global class NullPointerBatch implements Database.Batchable<sObject>, Database.Stateful{
    global Boolean hasError {get;set;}
    global NullPointerBatch(){
        //  hasError=False; // commented this intentionally to throw null pointer in the start method 
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query ='';
        if(hasError){ // the exception is thrown here
            query = 'select Id,Name From Contact';   
        return Database.getQueryLocator(query);
    global void execute(Database.BatchableContext BC,  List<sObject> scope) {

    global void finish(Database.BatchableContext BC) {


Technically this error should have sent me an email. In this case Im not recieving any emails. Whats even wierd is if i had any exceptions in process builder or flows, I was able to recieve the emails.

I’m looking at 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?.

Question: Can this be one of the suppression behavior or Can this be a bug or Am I missing something here?

Note: I’m the last modifed person and Yes Apex Exception Notification
is configured. Also as part of the support they made us do some testing by making us send some emails and declared everything is working as expected. So i wrote the above code to reproduce the behavior.

To tie the original question here. Did not receive exception email in production


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In your particular case where you’re deliberately generating the error, I’d expect some suppression (eventually)

If duplicate exceptions occur in Apex code that runs synchronously,
subsequent exception emails are suppressed and only the first email is

That is from And you will be generating a duplicate error over and over.

It looks like you’ve already done your reading around. From having read those Q/As before, I just came to the conclusion that you can’t rely on automated error emails from Salesforce. They don’t have a clear spec, and the behaviour is just unreliable. So, I end up building somethings myself by logging operations in the database and running reports/dashboards/workflow emails to alert about problems.

If something is critical, then pseudo-code:

insert status to say I will attempt X with status=running
try { 
  do X;
  update status to complete;
} catch(Exception e) {
  update status to error with exception details; 

Then run reports/workflows on any status objects that get stuck in running or end up in error.

Which doesn’t exactly answer your question, but might give you an alternative avenue because those error emails are rubbish.

Method 2

Well support was able to reproduce the issue and says that when an unhandled exception occurs, their system does throw an Internal Server Error type event in logs. They suspect, due to this ISE, apex exception email is getting suppressed and unable to send to the user.

They also pointed me to the idea
Need a reliable developer script exception alert mechanism

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x