+ Start a Discussion
NishaCNishaC 

Multiselect List problem

i have a multiselect list with values as this 

Days_collection__c = Monday am

                                        Monday pm

                                        Monday overnight 

                                        Tuesday am

                                                         pm

                                                         overnight

                                        Wednesday am

                                                               pm

                                                               overnight

and so on 

but i want to only week days from this list not with am,pm,overnight

but this is a multiselect list   so sometimes i have vallues like

        monday am,tuesday pm,wednesday,om,thrusday overnight,friday pm

how can i get only week days 

crop1645crop1645

Days_collection__c will be a string with semi-colon delimiters for each value.

 

You will need to use the String instance method 'split' to split first on semi-colon - resulting in a list of each picked value, then, for each picked value, split again on the space character. The [0] element in the resulting list from split will be the day of the week.  

 

Here's an example, i worked up using execute anonymous apex taht you can use as a basis

String[] resList = new List<String> ();
String s = 'Monday;Tuesday AM;Thursday overnight';
String[] itemList = s.split(';');
for (String item: itemList) {
   String[] token = item.split(' ');
   resList.add(token[0]);
}
System.debug(LoggingLevel.INFO,'resList=' + resList);

 This only works if there is a space between your picklist values as you noted in the problem statement

Anil MeghnathiAnil Meghnathi

 

 

String[] resList = new List ();

String s =[select Days_collection__c from SObjectName where Condition limit 1] .Days_collection__c;

String[] itemList = s.split(';');

for (String item: itemList)

{

String[] token = item.split(' ');

resList.add(token[0]);

}

 

 

restList contains all the days which are selected

Thanks