Skip to content

Instantly share code, notes, and snippets.

@emoran
Created July 29, 2014 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emoran/758df889ae53e20da526 to your computer and use it in GitHub Desktop.
Save emoran/758df889ae53e20da526 to your computer and use it in GitHub Desktop.
Send an email when an exception is catched.
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