+ Start a Discussion
rajesh k 10rajesh k 10 

How to display Multipicklist values as a checkboxes Dynamically comming Multipicklist fields in an visualforce page?

     Actually i displayed all fields dynamically in an visualforce page.I want In my fields Multipicklist fields are there .How to display Multipicklist fields as Checkboxes Dynamically?

help me.........
Hello Rajesh,

Please refer following thread for this requirement:

rajesh k 10rajesh k 10

Hi vinitha, 

                    In my visualforce page more than one multipicklists are there.How to find these multipicklists and automatically how to display those picklists values  as checkboxes.

Note:Not single field


You got to use 2 main elements here - 

1. Describe calls(they are free in Summer '14) - Get the options for required mutipicklist fields. Refer to picklist field describe methods

Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe() ;
Schema.SObjectType s = m.get('YOUR OBJECT') ;
Schema.DescribeSObjectResult r = s.getDescribe() ;

// Get all the fields 
Map<String, Schema.SObjectField> fields = r.fields.getMap() ;

// Can now retrieve a particular field and get additional properties
Schema.SObjectField f = fields.get('YOUR PICKLIST FIELD' ) ;
Schema.DescribeFieldResult r2 = f.getDescribe() ;
System.debug( 'OPTIONS '+r2.getPicklistValues() ) ;

// Collect r2.getPicklistValues() in list of select options and bind it with apex:repeat

2. apex:repeat - Use necessary repeats to iterate over no. of multipicklist fields and their options values.

rajesh k 10rajesh k 10
Hi ,
         This is my code help me....

<apex:repeat value="{!listObjectFields}" var="fieldAPIName">
             <apex:selectCheckboxes value="{!checkboxSelections}" layout="PageDirection">
    <apex:selectOptions value="{!MyCheckboxes}"/>
               <apex:inputField value="{!sObjectToBind[fieldAPIName]}"/>

public class DynaFieldSavePageCls {
// List<selectOption> options = new List<selectOption>();
public String selcheckboxString;
  private Map<String, String> fieldValueLabels = new Map<String, String>();

   private Map<String, Map<String,String>> fieldpicklists = new Map<String, Map<String,String>>();
  public List<SelectOption> options{get;set;}
     public list<selectOption> getMyCheckboxes(){

      string objectname ='rajesh__MForm__c';

list<SelectOption> options = new list<SelectOption>();

    Schema.sObjectType objType = sObjectToBind.getSObjectType();
      Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
    map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();

    for(Schema.SObjectField field : fieldMap.values())

      Schema.DescribeFieldResult fieldResult = field.getDescribe();
        if(fieldResult.getType() == Schema.DisplayType.MultiPickList) {
Schema.Picklistentry[] values = fieldResult.getPickListValues();

Map<String, String> picklists = new Map<String, String>();

for(Schema.Picklistentry val: values){
picklists.put(val.getLabel(), val.getValue());

fieldpicklists.put(fieldResult.getName(), picklists);
  options.add(new SelectOption(val.getValue(), val.getLabel()));
return options;


   public  List<String> checkboxSelections {get;set;}
  public void doSave()
if( sObjectToBind != null )
  insert sObjectToBind;

    public sObject sObjectToBind {get;set;}
    public List<String> listObjectFields {get;set;}
      public String strtemp;
   public DynaFieldSavePageCls()

     string objectname ='rajesh__MForm__c';

    listObjectFields =  new List<String>();
    Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
    Schema.sObjectType sObjType = globalDescription.get(objectname);

    //take care of the sequence of following 5 statements

    sObjectToBind = sObjType.newSObject();
    Schema.DescribeSObjectResult r1 = sObjType.getDescribe();
    List<User> lstUser = [ SELECT Id FROM User WHERE Username = 'rajesh060708@gmail.com' ];
if( sObjectToBind != null && lstUser != null && !lstUser.isEmpty() )
  sObjectToBind.put('OwnerId', lstUser[0].Id);

       Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();
    Integer i = 0;
    for(Schema.SObjectField field : mapFieldList.values())
        Schema.DescribeFieldResult fieldResult = field.getDescribe();
        if(fieldResult.isAccessible() && fieldResult.isUpdateable())