2

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;}
    //constructor
    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

3

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 sent.

That is from https://help.salesforce.com/articleView?id=code_apex_exceptions.htm&type=5. 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.

| improve this answer | |
1

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

| improve this answer | |

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.