here is the code,
I am getting test class error shown below:-System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: amit@abc.com;sudeep@abc.com: [toAddresses, amit@abc.com;sudeep@abc.com]List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(Label.CommunityContact);
mail.setToAddresses(sendTo);
mail.setReplyTo('noreply@salesforce.com');
List<String> ccTo = new List<String>();
mail.setCcAddresses(ccTo);
String Sub = 'Application Submitted for Group : ' + groupname;
mail.setSubject(Sub);
String body = 'An application for group membership has been submitted with the following information:<br />';
body += '<p><b>Name</b>: ' + firstName + ' ' + lastName + '<br>';
body += '<b>Company:</b> ' + company + '<br>';
body += '<b>Address:</b> ' + streetAddress + ' ' + streetAddressLine2 + '<br>';
body += '<b>City:</b> ' + city + '<br>';
body += '<b>State/Province/Region:</b> ' + stateProvinceRegion + '<br>';
body += '<b>Postal/Zip Code:</b> ' + postalZip + '<br>';
body += '<b>Country:</b> ' + country + '<br>';
body += '<b>Email:</b> ' + email + '<br>';
body += '<b>Job Title:</b> ' + jobTitle + '<br>';
body += '<b>Regional Account Manager Name:</b> ' + AMFirstName + ' ' + AMLastName + '<br>';
body += '<b>Disributor:</b> ' + Dist + '<br></p>';
mail.setHtmlBody(body);
mails.add(mail);
Messaging.sendEmail(mails);
Stack Trace: Class.GroupRegistrationController.registerUser: line 95, column 1 Class.GroupRegistrationControllerTest.testGroupRegistrationController: line 40, column 1Please help me to resolve this issue.Thanks,
Hello Amit, I think, the problem is due to worng email address.You can split the email address based on the delimeter ';' and cann all to the list. You can try this one -
List<String> sendTo = new List<String>();
sendTo.addAll((Label.CommunityContact).split(';'));
mail.setToAddresses(sendTo);
Please, let me know, if it helps you.
Thanks, Sumit Kumar Singh