function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sml9099sml9099 

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>
Ramu_SFDCRamu_SFDC
Please refer to the below article on more information about Wrapper class http://wiki.developerforce.com/page/Wrapper_Class

Below  post has more information on building wrapper class for multiple objects https://developer.salesforce.com/forums/ForumsMain?id=906F000000091yJIAQ