Can I access a lead's email history in Apex to see if they've already been sent an email from a timeframe/template combination? Or even something arbitrary like the email subject?
public void send() {
EmailTemplate emailTemplate = [SELECT Id, Name FROM EmailTemplate WHERE Name = 'Whatever'];
List<Messaging.SingleEmailMessage> emailBlast = new List<Messaging.SingleEmailMessage>();
List<Lead> leads = [SELECT Id, Email FROM Lead WHERE LastName = 'Recipients'];
for (Lead lead: leads) {
// if lead.emails includes 'Whatever' ??
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'[email protected]'};
mail.setToAddresses(toAddresses);
mail.setTargetObjectId(lead.Id);
mail.setTemplateId(emailTemplate.Id);
emailBlast.add(mail);
// end if
}
Messaging.SendEmailResult[] blastResults = Messaging.sendEmail(emailBlast);
}
Any ideas? If my question was unclear the comments in the code might help. Thanks.