You need to sign in to do that
Don't have an account?
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
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
This only works if there is a space between your picklist values as you noted in the problem statement
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