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
Manjunath BNManjunath BN 

Changing a picklist to multi select picklist

Hi all,

 

Is is possible to change a picklist to multiselect picklist on vf page based on the requirement.

 

For example: Multichannel is a field. If is true then that picklist must be multi select  and if it is no then it should be remain as a picklist.

 

How can I implement this in the VF page..............

 

Thanks in advance

 

 

Bhawani SharmaBhawani Sharma

 

 

//This method is to create a select option list for given Picklist Entries
public static List<SelectOption> getSelectOptionListByField(Schema.sObjectField sObjectField) {
		
		//Describe field and create a list of select options
		List<SelectOption> listOptions = new List<SelectOption>();
		
		//Get picklist entries and interate to display these in form of checkboxes
        List<Schema.PicklistEntry> pickListEntries = sObjectField.getDescribe().getPicklistValues();
        
        //loop throough the picklist entries and populate select list
        for (Schema.PicklistEntry pE : pickListEntries) {
         
            //Populate the select list with values
            listOptions.add(new SelectOption(pE.getValue() , pE.getLabel()));  
        }
        
        //Return list
        return listOptions;

 

Pass this method by passing the object picklist filed. Like: class.getSelectOptionListByField(Account.Type)

 

This will give you select option list that field. Now on page you can use this with multiselect attribute.

Use multiselect = false for single select and true for multiselect