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.
-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.
public class WrapNitesh {
//CONTROLLER CLASS
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));
}
// }
}
//### SELECTED ACCOUNT SHOWN BY THIS METHOD
public void ProcessSelected(){
selectedAccounts=new list<account>();
for(wrapaccount wrapobj:wrapaccountlist){
if(wrapobj.isSelected==true){
selectedAccounts.add(wrapobj.accn);
}
}
}
//##THIS IS WRAPPER CLASS
// account and checkbox taken in wrapper class
public class wrapaccount{
public account accn{get;set;}
public boolean isSelected{get;set;}
public wrapaccount(account a){
accn=a;
isselected=false;
}
}
}
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.
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
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.
Hi, 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..
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.
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,
http://2.bp.blogspot.com/-p8zeAeNXvNg/UgtB0_IbsNI/AAAAAAAAAqM/XVaKMjBu2s4/s1600/visualforce_wrapper_class.JPG
Also see the blogs for the wrapper class code below and further information,
http://sfdcgurukul.blogspot.sg/2013/08/what-is-wrapper-classhow-to-use-it-in.html
http://www.minddigital.com/what-is-wrapper-class-and-how-to-use-it-in-salesforce/
Regards,
Ashish
-i am giving code . only selected accounts are showed in the right side.
thanks,
http://www.forcexplore.com/2014/01/salesforce-interview-questions-2.html
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
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.
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..
https://success.salesforce.com/answers?id=90630000000hSoLAAU
this link will help u
Thanks so much for this code.it works
to learn concept easily
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.
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.
Hope this will help .
http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/
https://www.minddigital.com/what-is-wrapper-class-and-how-to-use-it-in-salesforce/
Use Wrapper Class to show data on the Visualforce Page Using Controller
https://sfdcadda.blogspot.in/2017/05/use-wrapper-class-to-show-data-on.html
https://cloudtechnzly.blogspot.in/2017/08/wrapper-class-examples-in-salesforce.html
Please visit for more detail,
https://www.sfdc-lightning.com/2018/10/wrapper-class-in-salesforce.html