function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SBNSBN 

Apex Schedular email notification

Hi ,

 

I have a requirement just to send an email notification every day to a particular user.I have implemented this using schedular apex class, but

 

I am not recievieng any emails at the scheduled time.Here is my code:

 

 

Global class Schedularclass implements Schedulable{
global void execute (SchedulableContext SC){
 {   
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  mail.setTemplateId('00Xi0000000ViBZ'); //email template id
  String[]   toAddresses = new String[]{'mygmailid@gmail.com'}; 

mail.setToAddresses(toAddresses);
 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}

 

Please let me know if anyone has any idea on this.

 

Thanks

SN

testrest97testrest97

you probably need a TargetObjectId when using a template. Generally User, Contact, or Lead

 

ex:

contact con=[Select id from contact limit 1];

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  mail.setTemplateId('00Xi0000000ViBZ'); //email template id

mail.setTargetObjectId(con.Id);
  String[]   toAddresses = new String[]{'mygmailid@gmail.com'}; mail.setToAddresses(toAddresses);
 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });