You need to sign in to do that
Don't have an account?

Wrapper class examples
Hi,
I am very new to salesforce can any one explain the exact what is wrapper class. Please give me new example with explanation and difference betweemal Apex class and wrapper class. Please give me the example using wrapper class and without wrapper class. Please don't give me the already available examples. Thanks!
I am very new to salesforce can any one explain the exact what is wrapper class. Please give me new example with explanation and difference betweemal Apex class and wrapper class. Please give me the example using wrapper class and without wrapper class. Please don't give me the already available examples. Thanks!
Wrapper is class or container whos instance is collection of other objects. In simple words it 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 single 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.It 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.
You can take help from the following program. It shows only selected accounts on right side.
I hope this helps you. You can even refer to the following link:
https://www.minddigital.com/what-is-wrapper-class-and-how-to-use-it-in-salesforce/ (https://www.minddigital.com/what-is-wrapper-class-and-how-to-use-it-in-salesforce/ )
Regards,
Ajay
wrapper class is a custom class which has different data types or properties as per requirement.
In simple words, creating a new custom class with two different data types. In this example I am creating a new custom class with two data types Name, and integer.
public class PieChartController {
public List<PieWedgeData> getPieData() {
List<PieWedgeData> data = new List<PieWedgeData>();
data.add(new PieWedgeData('Apex', 50));
data.add(new PieWedgeData('Visualforce', 30));
data.add(new PieWedgeData('Administration', 20));
return data;
}
// Wrapper class
public class PieWedgeData {
public String name { get; set; }
public Integer data { get; set; }
public PieWedgeData(String name, Integer data) {
this.name = name;
this.data = data;
}
}
}
Please mark it as Best answer if it is solves your problem.
Thank You,
Sohel Mohd
Here is visualforce page for above controller.
<apex:page controller="PieChartController" title="Pie Chart">
<apex:chart height="350" width="450" data="{!pieData}">
<apex:pieSeries dataField="data" labelField="name"/>
<apex:legend position="right"/>
</apex:chart>
</apex:page>
Please mark it as Best answer if it is solves your problem.
Thank You,
Sohel Mohd
1) http://amitsalesforce.blogspot.in/2016/03/wrapper-class-in-salesforce-select-all.html
Problem :-
How can I display a table of records with a check box and then process only the records that are selected?
Solution:-
Wrapper class.
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
Let us know if this will help you
Thanks
Amit Chaudhary
Thanks for the above replys. Can you please give the same example using without wrapper class isit possible . Let me know
Example to display two object data using wrapper class which do not have relationship in between them,
https://www.sfdc-lightning.com/2018/10/wrapper-class-in-salesforce.html