Wrapper Class

Wrapper Class in Apex Salesforce: A wrapper or container class is a class, a data structure which contains different objects or collection of objects as its members.

A wrapper class is a custom object defined by a programmer wherein he defines the wrapper class properties. Consider a custom object in salesforce, what do you have in it? fields right? different fields of different data types. Similarly wrapper class is a custom class that has different data types or properties as per requirement. We can wrap different object types or any other types in a wrapper class.

Wrapper Class in Apex Salesforce : A wrapper or container class is a class, a data structure which contains different objects or collection of objects as its members.

A wrapper class is a custom object defined by a programmer wherein he defines the wrapper class properties. Consider a custom object in salesforce, what do you have in it? fields right? different fields of different data types. Similarly wrapper class is a custom class that has different data types or properties as per requirement. We can wrap different object types or any other types in a wrapper class.

Below example, we have created our own list with two different data types.

public class wrapper {
/* Simple data type example
public void callwrapper(){
List<wrapperclass> lstwrapeer=new List<wrapperclass>();
wrapperclass wrapperObj=new wrapperclass();
wrapperObj.x=10;
wrapperObj.y='ranbir need Rs.';
lstwrapeer.add(wrapperObj);
system.debug(lstwrapeer);
}

public class wrapperclass{

public integer x;
public string y;
}
*/
public void callwrapper(){
List<wrapperclass> lst=new List<wrapperclass>();
//Account acc=[select id,name from Account];
contact cnn=[select id,firstname from contact limit 1];
for(Account acc_new:[select id,name from Account]){
wrapperclass obj=new wrapperclass(acc_new);
lst.add(obj);
}


wrapperclass obj1=new wrapperclass(cnn);
lst.add(obj1);
system.debug(lst.size());
}
public class wrapperclass{
public string name;
public wrapperclass(Account x1){
name=x1.name;
}
public wrapperclass(contact x1){
name=x1.firstname;
}

}
}

--

--

--

Salesforce Champion try to collect all the basic and important concept of the salesforce.I am passionate about my work. Because I love what I do, I have a steady source of motivation that drives me to do my best. Ambition and drive are two qualities of salesforce learner.

Recommended from Medium

✊✌✋ — A demo to evaluate react-three-fiber and its ecosystem

The revelation screen.

Beginner’s Guide to GraphQL in React Native & React(1/3)(Updated)

Taraxa Weekly Tech Update.

Non-Destructive Array Methods in JavaScript Pt. 1, Featuring .map()

How to Define PropTypes and Set Default Prop Values in

A Glance at Redux Toolkit

No overload matches this call with styled components TypeScript

Example No overload matches this call.

GraphQL Mutation & Subscription

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ranbir Kumar Das

Ranbir Kumar Das

I M Believer, Helper, Chaser, Thinker, Rich, Explorer, Prayer, Boss, Freedom, Fearless, Investor, Faith, Creator, trillionaire, CSM, Salesforce certified

More from Medium

Mock Objects in TDD

Integration

Slotly’s Guide for Meetings

How to Perform Functional API Testing Correctly