You need to sign in to do that
Don't have an account?
eric_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
Typically, to convert a MultiValue field into a list, you can use something like:
String [] s = [fieldname].split(';');
All Answers
Typically, to convert a MultiValue field into a list, you can use something like:
String [] s = [fieldname].split(';');
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;
}
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