1

I'm not sure what I'm doing wrong but I have been trying few different way but I still able to get only on record instead of getting two records, yes I double check the data do exists.

Here is the what I'm trying to do:

pull the list of names which is comma separated from the custom labels.

string commaSeparatedString = System.Label.DirectorList; // there are two names with comma separated
String[] myList = new List<String>();
myList = commaSeparatedString.split(','); 
System.debug('myList: ' + myList); //I see two names with comma separated
List<Account> rptList = [SELECT Id FROM Account WHERE Name IN : myList];
system.debug(rptList); //getting only one instead of two records.

My question: why is it showing only one record insterad of two records

my debug statement for : myList:

20:32:46:037 USER_DEBUG [11]|DEBUG|myList:  (John Doe,  
20:32:46:000 USER_DEBUG Jane Doe)

rptList:

20:47:43:025 USER_DEBUG [14]|DEBUG|(Account:{Id=0016w00000O7fKlAAJ, Name=Jane Doe})
2
  • Have you tried hand building your own list? Ie, String[] list = new String[]{'Jane Doe','John Doe'}; Account[] rptList = [SELECT Id, Name FROM Account WHERE Id IN: rptList]; - then you can look to see if there are any differences in your lists. Commented Dec 15, 2022 at 2:40
  • 4
    are there spaces in your custom label?
    – Nick C
    Commented Dec 15, 2022 at 2:49

2 Answers 2

0

The System.debug shows that you have a newline character in commaSeparatedString, this is culprit.
Fixing it is straightforward, just add a replace before the split:

String[] myList = commaSeparatedString.replace('\n', '').split(',');
System.debug('myList: ' + myList); // Now you should see the names on the same line
1

You have a new line character after comma in your DirectorList custom label. You need to put all values in your custom label in the same line, without any whitespaces before or after comma. Or you can include the whitespace in the split method, similarly to this: commaSeparatedString.split(',\n').

You must log in to answer this question.

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