function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Katherine RoweKatherine Rowe 

Unhandled exception sends email, can we stop that?

So apparently when there's an unhandled exception in a trigger, SF always sends an email to the person who is the Last Modified By person on the trigger/class? My question is, can we stop it from emailing anyone at all?

Disclaimer: Salesforce Admin here, not a developer. 

The reason I don't want it to try and send an email is, we have Email Deliverability set to System Only in our test and dev environments. And sometimes when an action leads to a trigger failing, the error displayed is about the "NO_MASS_MAIL_PERMISSION" instead of the underlying cause. If I turn Email Deliverability to All Emails, then a more relevant error message then shows in its place, and we can then figure out the problem and deal with it. The triggers I'm referring to are in a managed package, so rewriting the trigger to perhaps handle exceptions better is not in our control. So for now, I want to see if we can simply stop SF from trying to email anyone at all...

When unhandled Apex exceptions occur, emails are sent that include the Apex stack trace and the customer’s org and user ID. No other customer data is returned with the report. Unhandled exception emails are sent by default to the developer specified in theLastModifiedBy field on the failing class or trigger.

What Happens When an Apex Exception Occurs?

Error when Email Deliverability is set to System Only
User-added image

Error when Email Deliverability is set to All Emails
User-added image

Can your  SendMail method in trigger it should not be inside for loop.


I think you can add more email address to get the exception information, but not allowed to restrice the user of LastModified of class or trigger to get this inforamtion.

I am looking forward if someone provide another thoughts on this.

Ashlekh Gera 
Katherine RoweKatherine Rowe
Related to this problem, I came across this Salesforce article that mentions two settings:

"Respect SendEmail API" and "SendEmail API"

Where are these settings, they are something only Salesforce can set/see? What do they do, exactly? I tried to ask Salesforce Support these questions, but they said they can only help premier customers with developer questions like this.

Error When Sending Emails: NO_MASS_MAIL_PERMISSION