function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

what is a Wrapper class ? plz explain with example?

Hi Ajju, you need to spend some time looking over the training materials we have on this site.
Hi Ajay, 

A wrapper or container class is a class, data structure, or an abstract data type whose instances are a collections of other objects.It is a custom object defined by Salesforce developer where he defines the properties of the wrapper class. Within Apex & Visualforce this can be extremely helpful to achieve many business scenarios within the Salesforce CRM software.

Using Wrapper classes we can have the ability to check few records from the displayed list and process them for some action. 

See the example below,

Also see the blogs for the wrapper class code below and further information,


nitesh gadkarinitesh gadkari
-You can understand Wrapper like this.If you want to make a object which includes both( account and contact) or( account and its corresponding selection check box) you use wrapper class

-i am giving code . only  selected accounts are showed in the right side.
<apex:page sidebar="false" controller="WrapNitesh">

 <apex:form >
     <apex:pageBlock >
        <apex:pageBlockButtons >
          <apex:commandButton action="{!ProcessSelected}" value="Show Selected accounts" reRender="block2"/>
       <apex:pageBlockSection columns="2">
         <apex:pageBlockTable value="{!wrapaccountList}" var="waccl">
           <apex:column >
             <apex:facet name="header">
               <apex:inputCheckbox />
            <apex:inputCheckbox value="{!waccl.isSelected}" id="InputId"/>
            <apex:column value="{!}"/>
            <apex:column value="{!}"/>
            <apex:column value="{!waccl.accn.billingcity}"/>
          <apex:pageBlockTable value="{!selectedAccounts}" var="sa" id="block2">
            <apex:column value="{!}"/>
            <apex:column value="{!}"/>
            <apex:column value="{!sa.billingcity}"/>
public class WrapNitesh {


    public list<wrapaccount> wrapaccountList { get; set; }
    public list<account> selectedAccounts{get;set;}    

      public WrapNitesh (){
     //if(wrapaccountList ==null){
          wrapaccountList =new list<wrapaccount>();
          for(account a:[select id,name,billingcity,phone from account limit 10]){
           wrapaccountlist.add(new wrapaccount(a));
        // }

      public void ProcessSelected(){
     selectedAccounts=new list<account>();
      for(wrapaccount wrapobj:wrapaccountlist){
   // account and checkbox taken in wrapper class
   public class wrapaccount{
    public account accn{get;set;}
    public boolean isSelected{get;set;}
       public wrapaccount(account a){

Wrapper class in simple words is a custom defined type by programmer, whose structure will be defined as required by programmer. For example you may want to define a type that will conatin some account data+some images+some other custom object data. In order to accomodate this in a signle type you cannot use any standard salesforce type [list or set or any object] you will have to define your own type and that will be wrapper class.

Karamala DamodarKaramala Damodar
wrapper is class or container  whos instance is collection of other objects
the best example is u applied any jobs in websites the page look like checkbox job description aplly button three are different objects but all of then displayed in single page that is wrapper class
Hi Ajju,

After all above discussion only thing I can add is, Wrapper class is construction of an object in Apex code which can combine fields from different objects or a bunch of fields which you need only in Run time to achieve your goal. 
Sudeep DubeSudeep Dube
      Wrapper Class is collection of two or more diffrent objects. 
      So these are the abstract data structure by which a developer create its own data structure by groupuing another available data structure.
      It expands user capablity and give more power to developer a customized application. it can be user for creating Visualforce page where page contains Boolean as check box and list item as value..
Shephali SwarnkarShephali Swarnkar
Hi nitesh gadkari,
     Thanks so much for this works
Pavan kumar 546Pavan kumar 546
this was a fantastic explanation
 to learn concept easily
Amit SAmit S
Need help ppl!

I have a requirement to configure a Custom "View All" Button in Accounts View Related list for the Activities History.

On Click of the Button, The View should contain a List of Activities(Tasks) and a Long Text Area field from a Custom Object for each activity. 

Acvitity Record Id is stored in the Custom Object Field.

Can I use a Wrapper Class and add a list/field from the Custom Object instead of the Flag? Has anyone worked on a similar requirement. 
Arpita NayakArpita Nayak
Hi Nitesh,
Your example is very helpful.I tried this but i am unable to understand the flow.Can you please briefly explain the wrapper class code.
This gave me a good idea on the wrapper classes. Thanks All 
Thanks Everyone....!
Carl NielsenCarl Nielsen
So an apex class is similar to creating a ViewModel in an MVC app? If the page to be rendered is different to the domain model, controller must put all the relevant data into/outof a ViewModel class before rendering view / persisting to data store.
Arun Garg 9Arun Garg 9
Wrapper class Best Example with Code.
Use Wrapper Class to show data on the Visualforce Page Using Controller
Sekar Raj 8Sekar Raj 8
Wrapper class with checkbox(select option) example.
farukh sk hdfarukh sk hd
wrapper class is class whose instances are collection of objects.

Please visit for more detail,