1

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?

0

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}"/>
</apex:selectList>

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

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_selectoption.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.