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;
}
Thanks for sharing π its quite useful!!
Thanks it worked for my requirement… but i am getting both checkbox and radio buttons.. what could be the issue
ok but i selected multiple checkboxes after saving , only selected checkboxes will be save in Database how?please give me example
Use wrapper class
Hi, How to display dynamically comming multipicklist values as checkboxes dynamically in an visualforce page?