I am getting the below error when the below trigger is triggered. Can anyone tell me how to resolve this error -
Error -
Error: Invalid Data. Review all error messages below to correct your data. Apex trigger EmailService caused an unexpected exception, contact your administrator: EmailService: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, All targetObjectIds for an email must be of the same type.: []: Trigger.EmailService: line 20, column 1
Code -
trigger EmailService on Task__c (after insert) {
EmailTemplate et=[Select id from EmailTemplate where name='Multiple Tasks'];
List<Messaging.MassEmailMessage> mails = new List<Messaging.MassEmailMessage>();
for(Task__c t : Trigger.new)
{
if(t.Project_Approval__c =='Approved' &&t.Status__c == 'Open' ){
List<Id> lstIds= new List<Id>();
lstIds.add(t.Task_Executioner__c);
lstIds.add(t.Task_Executioner_1__c);
lstIds.add(t.Task_Executioner_2__c);
Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
mail.setTargetObjectIds(lstIds);
mail.setSenderDisplayName('Charan Tej');
mail.setTemplateId(et.id);
mails.add(mail);
}
}
Messaging.sendEmail(mails);
}