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
Lalit kumar 26Lalit kumar 26 

why am i getting this error while sending email to a list of recipients "Line: 11, Column: 1 System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing target address (target, to, cc, bcc): []"

public with sharing class EmailManager{

    public void sendMail(List<String> address, String subject, String body) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       String[] toAddresses = new String[] {address};
       // list<String> toAddresses = new list<String>();
            
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }

}
=================================================================
String[] toAddresses = new String[] {'lalitkumars1987@gmail.com', 'abc@gmail.com'};
//string address = 'abc@sfclouds.com';
String subject = 'Test Email';
String body = 'This is a test mail.';
EmailManager em = new EmailManager();

em.sendMail(toAddresses, subject, body);

----------------------------------------------------------------------------------------------------------------------------------
I am only able to send email to one address. But when i am sending to multiple recepients i am getting the above mentioned error.
Kindly correct it.
thanks
lalit
venkat-Dvenkat-D
public with sharing class EmailManager{

    public void sendMail(List<String> address, String subject, String body) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       //String[] toAddresses = new String[] {address};
       // list<String> toAddresses = new list<String>();
            
        mail.setToAddresses(address);
        mail.setSubject(subject);
        mail.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }

}

Try above code. Since  you are already passing list of string for toaddresses, you can directly set that in mail.
James LoghryJames Loghry
Hi there.  Whenever you post code in a question or solution, please use the code formatting button (< >).  This helps with readability and also allows repliers the ability to copy and paste if need be.  This applies for any sort of Apex, Visualforce, JavaScript, et al.  

Thank you!