Apex Exception Email to defined user

Apex Exception Email is going to, or released in winter 16 according to time you are reading this post.

What is Apex Exception Email:
    Before winter'16 when an Apex code encounters unhandled exception it sends the exception email to LastmodifiedBy user email address of the class or trigger.But now we can specify which user should receive the exception email.

Follow the below steps to add a apex exception email user:
     1. Go to setup
     2. Expand the 'Email Administration' under Administer.
     3. Click 'Apex Exception Email'.
     4. Click 'Add Salesforce User' button
     5. Select user and click save.

Now you have defined the apex exception user for your Salesforce org. From now if any apex exception occurs on your organization by any user then this defined user will receive an apex exception email. In the same page you can specify the 'To address' of the email received by the user in the 'External Email Addresses' field under 'Email Addresses Not in Salesforce' related list.

Below is the sample code to produce the apex exception:

Apex class:

public with sharing class Emailnotificationcheckcont {
    Account acc;
    public Emailnotificationcheckcont()
        acc=[select id,Name from Account where id='000199999999999999'];

Visualforce page:

<apex:page controller="Emailnotificationcheckcont">

Below is the URL to open the page in your org:


Replace this https://c.gus.visual.force.com/ with your org base url.

Once you open this page you will get an 'List has no rows for assignment to SObject' error and the above defined user will receive an email.If the user didn't receive an email check the below things in you org.

1. Email deliverability enabled atleast for system email.

2. Developer mode should be disabled for the user who received error on his screen.

I hope you find this article interesting, Rate this article if its useful to you.

Let me know your suggestions in comment section.

No votes yet