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
UncrasherUncrasher 

Mass Email Not working!!! Help Please

Hello,

 

The following code snippet is working from a compile and execute perspective; however, I never receive the email.  Does anyone have an idea why I cannot get this to work.  I wrote code to do single email and that works fine but for the admin email routine I want to send the same email to all active admins.  This code is in a troubleshooting mode and that is why you see hard coded stuff.  The id has been confirmed using Apex Explorer.

 

public void notifyAdmin() {
        string [] aa = new List<String>();
         
        List<User> adminList = [ Select u.Id, u.IsActive, u.ProfileId, u.Profile.Name from User u
                                 Where u.IsActive = true And u.Profile.Name = 'System Administrator' ];
        
        // Build array list of all active admininstrators
        for (User admins : adminList) {
            aa.add(admins.Id);
        }      
        
        /*
        User you = [ Select u.Id, u.IsActive, u.ProfileId, u.Profile.Name from User u
                                 Where u.IsActive = true And u.Profile.Name = 'System Administrator'
                                 And u.Id = '005A0000000M3SQIA0' ];                                  
        */
        
        //get the template used in this email
        EmailTemplate template = [ Select Id From EmailTemplate Where Name = 'ContactCompleteness' Limit 1 ];
    
        Messaging.MassEmailMessage email = new Messaging.MassEmailMessage();        
        email.setReplyTo('thomas.barrett@carefirst.com');
        email.setSaveAsActivity(false);  
        email.templateId = template.Id;          
        email.setTargetObjectIds(aa);
                            
        Messaging.SendEmailResult[] sendResult;
        //send the eMail
        sendResult = Messaging.sendEmail(new Messaging.MassEmailMessage[] { email });        
    }     

 

 

Thanks,

Tom