I am trying to send an email to the contact owner when the email on contact has bounced. Below is the code, it works and send email to the contact if I remove the IsEmail Bounced condition.
trigger testTrigger on Contact(after update) {
public Emailtemplate EmailBounced;
EmailBounced = [select id, name from EmailTemplate where name = 'Email Bounce mail template'];
for (Contact con: Trigger.New) {
if (con.email != null && con.isemailBounced == TRUE) {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTargetObjectId(con.ownerId);
email.setsaveAsActivity(FALSE);
email.setTemplateId(EmailBounced.id);
email.setSubject('Email Bounced Alert : Email does not exist');
if (con.ownerId != null) {
Messaging.sendEmail(
new Messaging.SingleEmailMessage[] {email});
system.debug('email sent ---------');
}
}
}
}
Tried with the workflow but not luck.
isemailBounced__c
get set? this is a custom field. How is it related to OOB fieldIsEmailBounced
?