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
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))];
system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+led);
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))];
system.debug('@*************************************'+led2);



for(Lead l:led)
{
leadid.add(l.id);
system.debug('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'+leadid);
}


for(Lead l:led1)
{
leadid.add(l.id);
system.debug('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'+leadid);
}


for(Lead l:led2)
{
leadid.add(l.id);
system.debug('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'+leadid);
}
Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
mail.setTargetObjectIds(leadid); // assign the all emails
//mail.setReplyTo('exemple@exemple.ex');
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 );
}
}

ReidCReidC