You need to sign in to do that
Don't have an account?
Error in sending Mass Email
Hi ,
In my visualforce page i have a table of records with checkbox to each of them. I want to send email to contacts of the selected records . I'm using a custom button for this.
Vf code for the button :-
apex:commandButton value="Send Email" action="{!SEmail}"/>
But i'm having issue with this.
Public PageReference SEmail(){
List<ID> MailCont = new List<Id>();
String Temp ='tempName';
Messaging.MassEmailMessage Email = new Messaging.MassEmailMessage();
Email.setTemplateId([Select id from EmailTemplate where Name =:Temp].Id);
System.debug('No of tdaw******************************************************' + tdaw.size());
for(Integer j=0;j<tdaw.size();j++){
System.debug('Value in toDelete***********************************' + tdaw[j].toDelete);
if(tdaw[j].isSelected == True )
{
MailCont.add(tdaw[j].tar.contact__c);
}
}
System.debug('Value in ids***********************************' + MailCont);
Email.setTargetObjectIds(MailCont);
Messaging.sendEmail(new Messaging.MassEmailMessage[] { Email });
return null;
}
While running i'm getting : SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing target object ids (contact, lead or user): []
Anybody has idea??
Thank you.
Savi3.
You need to add contact's email Id not Contact ID
MailCont.add(tdaw[j].tar.contact__c);
Correct above line.
Hi sai.sf,
Thanks for your reply. But i have a doubt..Email.setTargetObjectIds(MailCont); Here we can use only Contacts know??
Also in debug log , evenif i'm selecting rows from my page value for "isSelected" is false...