You need to sign in to do that
Don't have an account?
nununi
Help with Emailing via Apex Class
Hello Developers,
I need to write a schedulable apex class that sends email notifications to users who have not logged in the past 30 days. This is what I have so far but I am getting the error "Error: Compile Error: Method does not exist or incorrect signature: [Messaging.MassEmailMessage].setTargetObjectIds(LIST<User>) at line 12 column 17"
I am not sure where I am going wrong here.
I need to write a schedulable apex class that sends email notifications to users who have not logged in the past 30 days. This is what I have so far but I am getting the error "Error: Compile Error: Method does not exist or incorrect signature: [Messaging.MassEmailMessage].setTargetObjectIds(LIST<User>) at line 12 column 17"
I am not sure where I am going wrong here.
global class NotifyUsers implements Schedulable { global void execute(SchedulableContext ctx){ dateTime dt = date.today()-30; id sysAdm = [SELECT id from Profile where Name =: 'System Administrator' LIMIT 1].id; List <User> userList = [SELECT Name, Email, LastLoginDate, ISActive, Id From User WHERE IsActive = true AND LastLoginDate <: +dt AND Name != 'IRIS Help' AND ProfileId !=: sysAdm LIMIT 10000]; if(userList.size() > 0) { Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage(); mail.setTargetObjectIds(userList); // List of ids of the contact, lead, or User mail.setTemplateId('00***********XU'); // Id of the email template Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail }); } } }
List<Id> uids= new List<Id>();
for(User u: userlist)
uids.add(u.id);
on your line 12 replace userlist with uilds list.
mail.setTargetObjectIds(uids);