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
AngelikaAngelika 

Birthday Scheduler: Need help

I have written an Apex Scheduler class to send an email when a colleagues Birthday is 2 days away. I have created a contact with a birthday 2 days away. The contact's birthday is the July 29, 2012. Today's date is July 27, 2012. 

 

I'm stuck. I don't get an error message or anything. I have scheduled the class to run today at 12.  Please help!

 

 

global class BirthdayNameOptions implements Schedulable{
global void execute (SchedulableContext ctx)
{

sendBirthdayEmail();

}
public void sendBirthdayEmail()
{

for(Contact con : [SELECT Name FROM Contact WHERE Next_Birthday__c = : system.Today().addDays(2)])

{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId('00XJ0000000M31w');
mail.setTargetObjectId('005J0000000');
mail.setSaveAsActivity(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });
}
}


}

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Here is the problem...

 

mail.setTargetObjectId('005J0000000'); ->Id (UserID in your case) should be a proper 15 digit or 18 digit it...eg: 005E0000000V6RE

 

once you correct it you should be receiving email...