Activity Forums Salesforce® Discussions What is wrapper class in Salesforce?

  • shariq

    Member
    August 9, 2017 at 2:18 pm

    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.

  • Shaharyar

    Member
    August 9, 2017 at 4:09 pm

    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.

Popular Salesforce Blogs

Popular Salesforce Videos