Hello everyone, It's been so long since I posted my last post. I was little busy. Anyway, today I'm going to explain and show you all that what is wrapper class and how to use wrapper class in salesforce. And of course, how should I leave without giving example. So let's begin.
First of all, What is wrapper class?
- We all know that in salesforce it's quite easier to show only one objects data in visualforce page by using "pageblocktable" or "datatable".
- But what if we want to show two objects data into table which has no relationship with each other.
- Well, In that case we have to create one class that contains both of the objects and by using that wrapper class into our pageblocktable or datatable, we can access both of them objects fields.
- Above content was written as per my understanding. But as a definition wrapper class mean
"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."
- Now I'm going to show you how to use wrapper class in salesforce. In this example I'll create one visualforce page which contain all the accounts and every account will have one checkbox. Here is the thing, that checkbox in front of every account record can be achieved by wrapper class, let's start the example for giving you all broad idea.
Page Code :
Class Code :
OutPut :
After selecting some records.
So this is how it's done. I hope you guys understood what the wrapper class is and what is the use of it. Next time I'll come with more interesting and helpful topics. Until then have a nice coding. :)