Activity › Forums › Salesforce® Discussions › What is wrapper class in Salesforce?
Tagged: Help & Training, Salesforce Apex, Salesforce Development, Salesforce Visualforce, Wrapper, Wrapper Class
-
What is wrapper class in Salesforce?
Posted by Aman on August 9, 2017 at 2:13 PMWhy do we use wrapper class? Explain with example .
Shaharyar replied 8 years, 9 months ago 3 Members · 2 Replies -
2 Replies
-
Hi Aman,
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.
Here is the Example.
Hope this helps.
- [adinserter block='9']
-
Hello Aman,
Wrapper we can understand as the outer part of any kind of things (object like custom, standard, checkbox etc)that is wrapped with some kind of material.
A wrapper is a class or container whose instance is a collection of other objects.
The best example is when you apply for any jobs in websites the page looks like checkbox, job description, apply button, there are different objects but all of them displayed in a single page that is wrapper class
example..
public class MyClassContainer{ //main class
public List<wrapClass> new List<wrapClass>(); //instance of wrapper class
public class wrapClass{ //wrapper class
List<Account> acct{get;set;}
List<Opportunity> oppt{get;set;}
List<contact> cnct{get;set;}
public wrapClass(Account acct , Contact cnct , Opportunity oppt){
acct = new List<Account>();
oppt = new List<Opportunity>();
cnct = new List<contact>();
this.acct = acct;
this.cnct = cnct;
this.oppt = oppt;
}
}
}Here my class “MyClassContainer” contain three different collection object which is (List of Account, contact and Opportunity).
if we want to display three object which is Account, contact and Opportunity on one page then we make the instance of “MyClassContainer”
here the wrapper class comes into the picture.
Log In to reply.