Back
You can try with the below code this will help to achieve it:
global class BirthdayNameOptions implements Schedulable { global void execute (SchedulableContext ctx) { sendBirthdayEmail(); } public void sendBirthdayEmail() { List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for ( Contact con : [SELECT Id, Name FROM Contact WHERE Next_Birthday__c = : system.Today().addDays(2)] ) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTemplateId('00XJ0000000M31w'); mail.setTargetObjectId(con.Id); mail.setSaveAsActivity(false); mails.add(mail); } if ( mails.size() > 0 ) Messaging.sendEmail(mails, false); }}
global class BirthdayNameOptions implements Schedulable {
global void execute (SchedulableContext ctx) {
sendBirthdayEmail();
}
public void sendBirthdayEmail() {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for ( Contact con : [SELECT Id, Name FROM Contact WHERE Next_Birthday__c = : system.Today().addDays(2)] ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId('00XJ0000000M31w');
mail.setTargetObjectId(con.Id);
mail.setSaveAsActivity(false);
mails.add(mail);
if ( mails.size() > 0 )
Messaging.sendEmail(mails, false);
I hope this will help.
Want to know about Salesforce Apex? Prefer this tutorial on salesforce automation.
Want to become a Salesforce developer? join salesforce developer certification now!!
31k questions
32.8k answers
501 comments
693 users