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
vivek ravivivek ravi 

can any one say what error in this code

public PageReference send()
    {
        List<Contact> contacts=[Select Id,Email From Contact Where AccountId='001i000000g7erl'];
        List<Id> Conids=new List<string>();
        for(Contact mail: contacts)
        {
            Conids.add(mail.Email);
        }
       
        Messaging.MassEmailMessage emails=new Messaging.MassEmailMessage();
        emails.setTargetObjectIds(Conids);
        emails.setTemplateId('00Xi0000000J9hx');
        emails.setsubject('note');
        emails.setplainTextBody('body');
       
        Messaging.SendEmail(New Messaging.MassEmailMessage[] {emails});

return null;
}

when im clicking the send button
the error is ::System.StringException: Invalid id: vivekravi@gmail.com
Error is in expression '{!send}' in component <apex:commandButton> in page brand

this the error can any one solve this error for me
Sonam_SFDCSonam_SFDC
In the list type List<Id> you are trying to add Conids.add(mail.Email) which is giving you the error: Invalid id: vivekravi@gmail.com 

SFDC_DevloperSFDC_Devloper
@Vivek

  Try below Code...

<pre>
public PageReference send()
    {
     public List<Id> Conids=new List<string>();
        List<Contact> contacts=[Select Id,Email From Contact Where AccountId='001i000000g7erl'];
         Conids.add(Trigger.New[0].Id);
 
        Messaging.MassEmailMessage emails=new Messaging.MassEmailMessage();
        emails.setTargetObjectIds(Conids);
        emails.setTemplateId('00Xi0000000J9hx');
        emails.setsubject('note');
        emails.setplainTextBody('body');
      
        Messaging.SendEmail(New Messaging.MassEmailMessage[] {emails});

return null;
}
</pre>



Thanks,
Rockzz