You need to sign in to do that
Don't have an account?
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
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 });