Created
July 29, 2014 21:42
-
-
Save emoran/758df889ae53e20da526 to your computer and use it in GitHub Desktop.
Send an email when an exception is catched.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try{ | |
update account; | |
} | |
catch (DMLException e){ | |
ApexPages.addMessages(e); | |
Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage(); | |
String[] toAddresses = new String[] {'developer@acme.com'}; | |
mail.setToAddresses(toAddresses); | |
mail.setReplyTo('developer@acme.com'); | |
mail.setSenderDisplayName('Apex error message'); | |
mail.setSubject('Error from Org : ' + UserInfo.getOrganizationName()); | |
mail.setPlainTextBody(e.getMessage()); | |
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment