1

In below code semicolon separation not working for string with email addresses. Can someone help please?

Apex code

List<ABV_Form_Request_abv__c>  Useremails= ABV_Form_Request_abv__c.getAll().values();
        if(!Useremails.isEmpty()){
          system.debug('Useremails@@'+Useremails);
           for(ABV_Form_Request_abv__c Useremail : Useremails)
           {
               if(String.isnotBlank(Useremail.Email_abv__c)){
                   for(String estr : Useremail.Email_abv__c.split(';')){
                        if(string.isnotBlank(estr))
                            sendtoemail.add(estr);

..................................................
  • 2
    Can you add some input/output combos? Seems fine at first glance. – Adrian Larson Feb 24 '16 at 16:14
  • Put System.debug('Useremail.Email_abv__c ' + Useremail.Email_abv__c) before, after, and in your Ifs – EricSSH Feb 24 '16 at 16:21
  • Its a standard practice to separate emails with comma stackoverflow.com/a/12120203/1343065, are you sure its semicolon and not comma ? – karthikselva Feb 24 '16 at 16:24
  • If not careful, by using semicolons, you could easily be creating lists of strings instead of a single string of email addresses, esp if using brackets [] followed by {} curly braces notation (in source code for emails that is). – crmprogdev Feb 24 '16 at 18:15
  • Can you maybe post an example string you are trying to split? – cricketlang Feb 24 '16 at 18:49
2

Definitely is not an issue with splitting the string, simplified the code a bit and ran the following in the execute anonymous window to demonstrate:

List<String>  Useremails = new List<String>{
    'first@second.com;second@first.com',
    'third@fourth.com;fourth@third.com',
    'fifth@sixth.com', 'six@seven.com'};
List<String> emailResults = new List<String>();

for(String Useremail : Useremails) {
    for(String email : Useremail.split(';')){
        emailResults.add(email);
        System.debug(email);
    }
}

System.debug(emailResults);

debug results

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.