You need to sign in to do that
Don't have an account?
Julio S
Send an email to an external email address when a task is created with specific subject
Hi Devs,
Is it possible to send a notification to a user, or to an external email address when there is a task created on a contact record with a specific subject (Task subject). Please advise, Im quite noob on coding with apex.
Thanksm
Julio
Is it possible to send a notification to a user, or to an external email address when there is a task created on a contact record with a specific subject (Task subject). Please advise, Im quite noob on coding with apex.
Thanksm
Julio
Trigger
Here is the class to send an EmailManager
All Answers
Trigger
Here is the class to send an EmailManager
Error: Compile Error: A non foreign key field cannot be referenced in a path expression: WhoId at line 5 column 17
Error: Compile Error: Unexpected token '{'. at line 1 column 14
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger SendEmailNotification caused an unexpected exception, contact your administrator: SendEmailNotification: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile.: []: Class.SomeClass.sendMail: line 13, column 1
public class SomeClass {
// Public method
public void sendMail(String address, String subject, String body) {
// Create an email message object
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {address};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);
// Pass this email message to the built-in sendEmail method
// of the Messaging class
Messaging.SendEmailResult[] results = Messaging.sendEmail(
new Messaging.SingleEmailMessage[] { mail });
// Call a helper method to inspect the returned results
inspectResults(results);
}
// Helper method
private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
Boolean sendResult = true;
// sendEmail returns an array of result objects.
// Iterate through the list to inspect results.
// In this class, the methods send only one email,
// so we should have only one result.
for (Messaging.SendEmailResult res : results) {
if (res.isSuccess()) {
System.debug('Email sent successfully');
}
else {
sendResult = false;
System.debug('The following errors occurred: ' + res.getErrors());
}
}
return sendResult;
}
}