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
zalagk641.3958165242554043E12zalagk641.3958165242554043E12 

Email Message missing dynamic list to be mention.

Hello i want to add list people having Birth day from custom objectto all other people except Birthday people list,but can send email but of people missing in template. find below sample code.

public void sendBirthdayEmail()
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
 
Map<String,List<student__c>> emailstudentMap = new Map<String,List<student__c>>();
List<String> ToAddresses=new List<string>() ;
List<student__c> studenthavingBday=[SELECT id, Name,email__C FROM student__c WHERE Next_Birthdate__c = : system.Today().addYears(1)] ;
system.debug('test start having'+ studenthavingBday);
    //where Next_Birthdate__c <>: system.Today().addYears(1)
     List<student__c> SList1 =[Select Id, Name, Email__c from student__c where Next_Birthdate__c <> : system.Today().addYears(1)];
   
       for(student__c se:SList1)
       {
           ToAddresses.add(string.valueOf(se.Email__c));
           
       }
        system.debug('who will in list:'+ SList1);
        system.debug('who will get email:'+ ToAddresses);
    
                    mail.setTemplateId('00Xi0000000FuvA');  //this id is of birhday reminder template        
                    mail.setToAddresses(ToAddresses);

mail.setTargetObjectId('01Ii0000002FE4n');//student object target

mail.setSaveAsActivity(false);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });

} }