Display a Multi-picklist as Checkboxes

Assume Military_Branches__c is of multipicklist type but you want to display it as check boxes on VF page.

Task1: created a VF page and write following codes between pageblocksection.

 







Task 2: create a method in controller which will return the list of selectOptions


public List militaryBranch{get;set;} //this will contain the values of selected checkboxes
public List getMilitaryBranches() {
list options = new list();
try {
//Military_Branches__c is a multipicklist
Schema.DescribeFieldResult fieldResult = Contact.Military_Branches__c.getDescribe();
list values = fieldResult.getPickListValues();
for (Schema.PicklistEntry a : values) {
options.add(new SelectOption(a.getLabel(), a.getValue()));
}
} catch (Exception e) {
ApexPages.addMessages(e);
}
return options;
}

Published by Sandeep Kumar

He is a Salesforce Certified Application Architect having 11+ years of experience in Salesforce.

5 thoughts on “Display a Multi-picklist as Checkboxes

  1. Thanks it worked for my requirement… but i am getting both checkbox and radio buttons.. what could be the issue

Leave a Reply