Created
September 13, 2018 15:36
-
-
Save danic85/0a0cb001b6a8415ff139c55bd4c98170 to your computer and use it in GitHub Desktop.
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
/* Example for sending an email when there is an error on a JSON request */ | |
private static void sendErrorEmail(String method, HttpResponse response, String requestJSON) { | |
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); | |
message.toAddresses = new String[] { 'me@example.org' }; | |
message.subject = 'Error in ' + method + ' : ' + response.getStatusCode() + ' - ' + response.getStatus(); | |
if (requestJSON == '' || requestJSON == null) | |
message.plainTextBody = 'No body'; | |
else message.plainTextBody = requestJSON; | |
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message}; | |
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); | |
if (results[0].success) | |
{ | |
System.debug('The email was sent successfully.'); | |
} else | |
{ | |
System.debug('The email failed to send: ' + results[0].errors[0].message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment