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
pj_27pj_27 

Apex Scheduler Help needed

Hi,

I am a beginner with apex scheduling and I want to send email to the contacts on their respective birthdays.

I have developed a code but somehow it is not working.

Any help or suggestion appreciated. Thank you in advance.

 

******************************************************************************

Code  -

******************************************************************************

global class ContactmailScheduler implements Schedulable
{
    global void execute(SchedulableContext ctx)
    {
           SendMassEmail Objsme = new SendMassEmail();
           Objsme.sendmail();
    }     
        
}

******************************************************************************

public with sharing class SendMassEmail   
{
    List<Id> ConIdList = new List<Id>();
        
    public void sendmail()
    {
        ContactmailScheduler nd = new ContactmailScheduler();  
        String asd = '0 0 13 * * ?';
        System.schedule('Send mail',asd,nd);
    
        List<Contact> cntlst = [Select c.Birthdate,c.Id,c.Name from Contact c where c.active__c =true AND
        c.Birthdate = THIS_MONTH ];
          
          if(cntlst.Size()> 0 )
        {
            for(Contact objCon : cntlst )
              {    
                  if(objCon.Birthdate.day()== Date.today().day())
                   ConIdList.add(objCon.Id);
              }
        }
            
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setTargetObjectIds(ConIdList);
        mail.setTemplateId('00X90000000SuQ8');
        mail.setUseSignature(true);
        Messaging.sendEmail(new messaging.Massemailmessage[] {mail});    
    }
                
}

ziaullahkhaksarziaullahkhaksar

Please any body Help Me...

i want to sent an-email to my all contacts through Apex Shedular,

thank u so much in advance.