Wednesday, 22 October 2014

Displaying a picklist in Mulit Select Checkbox format in Salesforce

Hi All,

Generally we provide flexibility to user so that user can select multiple value form a picklist at a time. This post is only for displaying a pick-list in multi select check-box format.  

Here is the page:-

<apex:page controller="multiselectCheckboxController ">
    input[type='checkbox'] {
        border: 1px solid #aaa;
        display: block;
        <apex:pageBlockSection columns="1">
            <apex:pageblocksectionitem >          
                <apex:outputlabel value="Industory" />
                <apex:selectcheckboxes layout="pageDirection" value="{!Industoryname}">                   
                    <apex:selectoptions value="{!Industorynames}" />          


Controller :--

public class multiselectCheckboxController {

    public List<string> Industoryname{get;set;}

public multiselectCheckboxController () 
        Industoryname =new List<String>();

public List<selectoption> getIndustorynames()
        list<selectoption> options = new list<selectoption>();            
        //Product Name is a MultiSelect Picklist               
        Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();

        list<schema.picklistentry> values = fieldResult.getPickListValues();               
        for (Schema.PicklistEntry a : values) 
        options.add(new SelectOption(a.getLabel(), a.getValue()));
        catch (Exception e) 
        system.debug('## Product Name Options'+ options);          
        return options;