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