function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
eric_wceric_wc 

Multi-select values into list variable

I am trying to figure out how to load a multi-select field values in to a list variable so I can loop through the list using the values in a query.

 

For example multi-select list contains a,b,c,d,e

b and d are selected so if I query the field i get back b;d

how do I get b;d loaded in to a list var  x  so I can use each of them in a query

 

for ...

select * from sobject where name =  x

 

 

I know this has to be possible but not being a developer I have not been able to figure out how.

Any help would be much appreciated

Thanks

Eric

 

 

Best Answer chosen by Admin (Salesforce Developers) 
BritishBoyinDCBritishBoyinDC

Typically, to convert a MultiValue field into a list, you can use something like:

 

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

 

 

All Answers

BritishBoyinDCBritishBoyinDC

Typically, to convert a MultiValue field into a list, you can use something like:

 

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

 

 

This was selected as the best answer
Pradeep_NavatarPradeep_Navatar

Tryout this sample code to bind the multipicklist values in controller.

 

VF code:

                                                     <apex:selectList size="8" value="{!selcdaysntimes}" multiselect="true" style="z-index:-1;">

                                                                <apex:selectOption itemLabel="Sunday Morning" itemValue="Sunday Morning"/>

                                                                <apex:selectOption itemLabel="Sunday Afternoon" itemValue="Sunday Afternoon"/>

                                                                <apex:selectOption itemLabel="Sunday Evening" itemValue="Sunday Evening"/>

                                                                <apex:selectOption itemLabel="Monday Morning" itemValue="Monday Morning"/>

                                                                <apex:selectOption itemLabel="Monday Afternoon" itemValue="Monday Afternoon"/>

                                                                <apex:selectOption itemLabel="Monday Evening" itemValue="Monday Evening"/>

                                                </apex:selectList>

 

 

Controller code:

                                                public List<String> selcdaysntimes{get;set;}

                                                public void creatVolOpp()

                                                {

                                                                String daysntimes = '';

                                                                Occurrence__c occ = [Select id from occurrence__c where volunteer_opportunity__c =:volid];

                for(String i: selcdaysntimes)

                {

                    if(daysntimes =='')

                    {

                        daysntimes = i;

                    }

                    else

                    {

                        daysntimes = i +';'+ daysntimes;

                    }

                }

                occ.Days_Times_Needed__c = daysntimes;

                                                                update occ;

                                    }

eric_wceric_wc

British Thanks I think that is what I was looking for.

 

Pradeep thank you for the code sample but I don't think it will do what I am looking for.

 

Thank you guys for taking the time to reply

Eric