-2

Following code showing error :

EXCEPTION_THROWN [105]|System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid:


    List<String> sendTo = new List<String>();
    sendTo.addAll((System.Label.GratisOrderServiceEmail).split(';')); //for list of recepeint
   // system.debug(sendTo);
    mail.setToAddresses(sendTo); 
1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Mar 5 at 18:04

1 Answer 1

1

You have any of (a) a leading semi-colon, (b) a trailing semi-colon, or (c) multiple semi-colons in succession. For example, ;[email protected];;[email protected]; would have a total of 3 empty strings, which are not valid emails.

You can fix your code by checking for empty values.

Set<String> emails = new Set<String>(System.Label.GratisOrderServiceEmail.split(';'));
// Ignore blank values
emails.remove('');
sendTo.addAll(emails);

Not the answer you're looking for? Browse other questions tagged .