In the Opportunity record I have a custom field of type lookup field . In the lookup field programmatically via apex I add and remove values.

objOpportunity.userIdToPressUnlock__c = UserInfo.getUserId();

But I need to change the type of the custom field from lookup to multiselect picklist. For that reason I also have to make changes in the apex code in order to be able to add and remove new values form the multiselect picklist.

Could you please explain how to add and remove values from the multiselect picklist programmatically by using apex code?


1 Answer 1


Just define a field in your controller

private List<SelectOption> someOptions = new List<SelectOption>{
    new SelectOption('One','One'),
    new SelectOption('Two','Two'),
    new SelectOption('Three','Three')

on particular events/actions - manipulate the items in list

on visualforce page use this field for select options

<apex:selectList id="someSelection" value="{!someValue}" multiselect="true" >
  <apex:selectOptions value="{!someOptions}"/>

More info here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm


You must log in to answer this question.

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