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
Savi3Savi3 

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.


sai.sfsai.sf

You need to add contact's email Id not Contact ID

 

 MailCont.add(tdaw[j].tar.contact__c);

 

 

Correct above line.

Savi3Savi3

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...