In below code snippet , What
is your observation and what is going wrong ? *
trigger TestBeforeDelete on
Lead (before Delete) {
for(Lead l : Trigger.Old)
{
l.addError('error');
}
String msgBody = 'Test Email';
String Subject = 'Test from Cogni Force
on Lead';
Messaging.SingleEmailMessage mail = new
Messaging.SingleEmailMessage();
String[] toAddresses = new String[]
{'abc@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('abc@gmail.com');
mail.setSenderDisplayName('Cogniforce
Test Simulator');
mail.setSubject(Subject);
mail.setPlainTextBody(msgBody);
mail.setHTMLBody(msgBody);
Messaging.sendEmail(new
Messaging.SingleEmailMessage[] { mail });
}
It
will not send any email. Because “adderror” prevents all transactions from
committing including emails
This comment has been removed by the author.
ReplyDelete