You need to sign in to do that
Don't have an account?

Mass Email using Custom label : Test Class Issue
Hi Team,
I want to send email to number of users, for this I am storing 'toaddress' in custom label.
here is the code,
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);
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]
Stack Trace: Class.GroupRegistrationController.registerUser: line 95, column 1 Class.GroupRegistrationControllerTest.testGroupRegistrationController: line 40, column 1
Please help me to resolve this issue.
Thanks,
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 - Please, let me know, if it helps you.
Thanks,
Sumit Kumar Singh
All Answers
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 - Please, let me know, if it helps you.
Thanks,
Sumit Kumar Singh
So you need to convert the label to string array first.
It is working fine now.