+ Start a Discussion
chowdary marellachowdary marella 

Schedular class

Hi all i had written a class, due_date__c is date/Time field in Lead
Requirement:-I need due date reminders sent to whomever sets the due date. For example, if an agent completes a task then sets a date for the next action, a reminder needs to go to that agent to remind him/her that they have tasks to complete. Reminders should come the day before the event is due, again at 3 hours before due date and then one hour before due date.

need to schedule before 3hrs,before 1day and before 1 hour.

QUdos in Advance..Thank uu



My code


global class Sending_Email_SINGLECLASS implements Schedulable
public List<Lead> led=new List<Lead> ();
public list<lead> led1= new List<Lead> ();
public List<Lead> led2=new List<Lead> ();
list<id> leadid=new list<id>();

global void execute(SchedulableContext ctx)

Datetime d=system.TODAY();

 led=[select id,DUEDATETIME__c,Email from lead where DUEDATETIME__c=:date.valueOf(d.addHours(-1))];
led1=[select id,DUEDATETIME__c,Email from lead where DUEDATETIME__c=:date.valueOf(d.addHours(-2))];
system.debug('@++++++++++++++++++++++++++++++++++++++'+led1); */
led2=[select id,Due_Date__c,Email from lead where Due_Date__c=:date.valueOf(d.adddays(-1))];

for(Lead l:led)

for(Lead l:led1)

for(Lead l:led2)
Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
mail.setTargetObjectIds(leadid); // assign the all emails
EmailTemplate et= [SELECT id FROM EmailTemplate WHERE developerName = 'birth_day'];
mail.setSenderDisplayName('SirdikChowdary Marella'); // displaying the senders name
mail.setTemplateId(et.id); // adding the templete id,here we are taken subject,body.
Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
system.debug('********mail *@@@@@@@'+mail );