You are using an older browser that might negatively affect how this site is displayed. Please update to a modern browser to have a better experience. Sorry for the inconvenience!

Wrapper Class with Multi-Select Picklists

By: Radha


A wrapper or container class is a class, a data structure, or an abstract data type which contains different objects or collection of objects as its members.

A wrapper class is a custom object where the wrapper class properties are defined. Consider a custom object in Salesforce. It contains different fields of different data types. Similarly, wrapper class is a custom class which has different data types or properties. As per requirement, we can wrap different object types or any other types in a wrapper class.

The Example below shows how to display the multi-select picklists using the wrapper class.

Step 1: Create a Visualforce page 


<apex:page controller="multiselect" > 


        <apex:outputPanel id="out"> 

    <center><apex:outputText value="Wrapper class with multi-select picklists" style="font-style:normal;font-weight:bold;font-size:18px;text-align:center;width :100%;"> 



            <table border="1" style="position: relative;left:37%;"> 

                <apex:repeat value="{!Lists}" var="l"> 



                            <apex:selectList value="{!l.countries}" multiselect="true"> 

                                <apex:selectOptions value="{!l.items}"/> 




                            <apex:actionstatus id="status" startText="testing..."> 

                                <apex:facet name="stop"> 


                                        <p>You have selected:</p> 

                                        <apex:dataList value="{!l.countries}" var="c">{!c}</apex:dataList> 










        <center><apex:commandButton value="Submit" action="{!test}" status="status"/></center> 



Step 2: Create a Controller class for the Visualforce page 


public class multiselect{ 

    public List<selectList> lists {get; set;}  

    public multiselect() { 

        lists = new List<selectList>(); 

        for (Integer i = 0; i < 3; i++) { 

            lists.add(new selectList(i)); 



    public PageReference test() { 

        return null; 


    public class selectList { 

        Integer intValue; 

        String[] countries = new String[]{}; 


        public selectList(Integer intValue) { 

            this.intValue = intValue; 


        public List<SelectOption> getItems() { 

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

            options.add(new SelectOption('Value:' + intValue + ' - US','Label:' + intValue + ' - US')); 

            options.add(new SelectOption('Value:' + intValue + ' - CANADA','Label:' + intValue + ' - Canada')); 

            options.add(new SelectOption('Value:' + intValue + ' - MEXICO','Label:' + intValue + ' - Mexico')); 

            return options; 


        public String[] getCountries() { 

            return countries; 


        public void setCountries(String[] countries) { 

            this.countries = countries; 




In this controller apex class, we have used a wrapper class selectList in which we define the multi-select picklist values by using the getter and setter methods.

Step 3: Execute the Visualforce page 

wrapper class in salesforce

The Visualforce page displays a table with multi-select picklist field in the first column, and if one or more values are selected, the selected values will be displayed in the second column.


wrapper class in salesforce

Reference Link: Wrapper class