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

Wrapper class to display multiple objects in Visualforce table
Hey,
I have Custom object "site_placement__c" . It's child object is "site_placement_audience__c". I have created a VF page which fetch the records from "site_placement__c" object based on a "device_type__c" field. It displays the records in a table. I also want to display the "impression_share__c" field from "site_placement_audience__c" along side in the table. I have read online that I need to create wrapper class for this . But I could not understand wrapper class. Can someone help me in understanding wrapper class and how to solve this. Below is my apex class and Page
Apex class
public class Fetchsiteplacementmulti{
String devicetype;
public Site_Placements__c sp{get;set;}
public List<Site_Placements__c > spRec{get;set;}
public Fetchsiteplacementmulti()
{
sp=new Site_Placements__c ();
spRec = new List<Site_Placements__c>();
}
public void FillAggregates(){
String devicetype= '';
string[] lststr=sp.New_Device_Type__c.split(';');
for (String s: lststr) {
devicetype+= '\'' + s + '\',';
}
devicetype= devicetype.substring (0,devicetype.length() -1);
String sitePlacementQuery ='SELECT Id,Name,Site_Level_Max_Impressions__c , Site_Placement_ID__c from Site_Placements__c WHERE New_Device_Type__c INCLUDES (' + devicetype + ') ORDER BY Site_Level_Max_Impressions__c DESC limit 10';
spRec=database.query(sitePlacementQuery);
}
}
Visualforce Page:
<apex:page controller="Fetchsiteplacementmulti" tabStyle="Site_Placements__c" sidebar="True">
<apex:form >
<apex:pageBlock >
<apex:messages />
<apex:pageBlockButtons location="Both">
<apex:commandButton value="Fetch" action="{!FillAggregates}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
</apex:pageBlockSection>
<apex:pageBlockSection title="Please select the Critirea">
<apex:pageBlockSectionItem >
<apex:outputLabel value="device" for="autoplay"/>
<apex:inputField value="{!sp.New_Device_Type__c}" id="autoplay"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Results">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!spRec}" var="site" columnsWidth="500px, 500px" >
<apex:column value="{!site.Name}"/>
<apex:column value="{!site.Site_Placement_ID__c}"/>
<apex:column value="{!site.Site_Level_Max_Impressions__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
I have Custom object "site_placement__c" . It's child object is "site_placement_audience__c". I have created a VF page which fetch the records from "site_placement__c" object based on a "device_type__c" field. It displays the records in a table. I also want to display the "impression_share__c" field from "site_placement_audience__c" along side in the table. I have read online that I need to create wrapper class for this . But I could not understand wrapper class. Can someone help me in understanding wrapper class and how to solve this. Below is my apex class and Page
Apex class
public class Fetchsiteplacementmulti{
String devicetype;
public Site_Placements__c sp{get;set;}
public List<Site_Placements__c > spRec{get;set;}
public Fetchsiteplacementmulti()
{
sp=new Site_Placements__c ();
spRec = new List<Site_Placements__c>();
}
public void FillAggregates(){
String devicetype= '';
string[] lststr=sp.New_Device_Type__c.split(';');
for (String s: lststr) {
devicetype+= '\'' + s + '\',';
}
devicetype= devicetype.substring (0,devicetype.length() -1);
String sitePlacementQuery ='SELECT Id,Name,Site_Level_Max_Impressions__c , Site_Placement_ID__c from Site_Placements__c WHERE New_Device_Type__c INCLUDES (' + devicetype + ') ORDER BY Site_Level_Max_Impressions__c DESC limit 10';
spRec=database.query(sitePlacementQuery);
}
}
Visualforce Page:
<apex:page controller="Fetchsiteplacementmulti" tabStyle="Site_Placements__c" sidebar="True">
<apex:form >
<apex:pageBlock >
<apex:messages />
<apex:pageBlockButtons location="Both">
<apex:commandButton value="Fetch" action="{!FillAggregates}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
</apex:pageBlockSection>
<apex:pageBlockSection title="Please select the Critirea">
<apex:pageBlockSectionItem >
<apex:outputLabel value="device" for="autoplay"/>
<apex:inputField value="{!sp.New_Device_Type__c}" id="autoplay"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Results">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!spRec}" var="site" columnsWidth="500px, 500px" >
<apex:column value="{!site.Name}"/>
<apex:column value="{!site.Site_Placement_ID__c}"/>
<apex:column value="{!site.Site_Level_Max_Impressions__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Below post has more information on building wrapper class for multiple objects https://developer.salesforce.com/forums/ForumsMain?id=906F000000091yJIAQ