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

What is wrapper class?
Hi everyone. newbie here does anyone can explain me what is wrapper class particularly in apex programming what is the usage of this . thanks
You need to sign in to do that
Don't have an account?
Hi everyone. newbie here does anyone can explain me what is wrapper class particularly in apex programming what is the usage of this . thanks
when should i use wrapper class?
Here is the complete explanation with example. Hope it will clear all your queries.
http://wiki.developerforce.com/page/Wrapper_Class
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Wrapperclass to join two unrelated custom objects.
obj1 - Student (Id, Name)
obj2 - Subject (Id & amount)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class wrapperClassController{
public List<cStudentDetail> stsubject {get; set;}
//constructor that populates the wrapper class with data and
//the updates the list that is exposed to the VF page
public wrapperClassController(){
stsubject = new List<cStudentDetail>();
for (Student__c sd: [select id__c, name__c from Student__c]){
for (Subject__c sb: [select id__c,amont__c from Subject__c]){
cStudentDetail stsud = new cStudentDetail();
stsud.StudentId = sd.id__c;
stsud.StudentName = sd.name__c;
stsud.SubjectId = sb.id__c;
stsud.SubjectAmount = sb.amont__c;
stsubject.add(stsud);
}
}
}
//wrapper class has custom fields to hold values from both the objects
public class cStudentDetail{
public string StudentId {get; set;}
public string StudentName {get; set;}
public string SubjectId {get; set;}
public string SubjectAmount {get; set;}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<apex:page controller="wrapperClassController">
<apex:pageBlock >
<apex:dataTable value="{!stsubject}" var="s" cellPadding="4" border="1">
<apex:column >
<apex:facet name="header">StudentID</apex:facet>
{!s.StudentId}
</apex:column>
<apex:column >
<apex:facet name="header">StudentName</apex:facet>
{!s.StudentName}
</apex:column>
<apex:column >
<apex:facet name="header">SubjectID</apex:facet>
{!s.SubjectId}
</apex:column>
<apex:column >
<apex:facet name="header">SubjectAmount</apex:facet>
{!s.SubjectAmount}
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:page>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------