+ Start a Discussion
RudiHulsbosRudiHulsbos 

Add another object to wrapper class

Hi All,

 

I have managed to create a wrapper class containing a list of Contacts. I now need to add data from another object to each Contact to display in a large data table in a visual force page. How would i go about doing this? All the examples in the community cover how to add a check box next to each contact, but this not what i want to do.

 

I have attached my controller code and vf page. The second SELECT statement is the object info that i need returned. 

 

 

Please help! 

 

Thanks,

 

Rudi 

<apex:page id="Page" controller="dataTableContacts" sidebar="false" showHeader="true" tabStyle="Contact" contenttype="application/vnd.ms-excel#Invitation.xls" cache="true" ><apex:form > <apex:pageBlock title="Invitation Tracking" > <apex:dataTable value="{!Contacts}" var="c" border="2" width="75%" title="Invitation Tracking"> <apex:column width="5%"> <apex:facet name="header">Project</apex:facet> <apex:outputPanel layout="block" style="width:100%;overflow:hidden"> <apex:outputText value="{!c.contactlist.Project__c}"/> </apex:outputPanel> </apex:column> <apex:column > <apex:facet name="header">Name</apex:facet> <apex:outputPanel layout="block" style="width:100%;overflow:hidden"> <apex:outputText value="{!c.contactlist.Name}"/> </apex:outputPanel> </apex:column> <apex:column > <apex:facet name="header">Member Source</apex:facet> <apex:outputText value="{!c.contactlist.Member_Source__c}"/> </apex:column> <apex:column > <apex:facet name="header">Member</apex:facet> <apex:outputText value="{!c.contactlist.Member__c}"/> </apex:column> <apex:column > <apex:facet name="header">Date of CAL Approval</apex:facet> <apex:outputText value="{!c.contactlist.Date_of_CAL_Approval__c}"/> </apex:column> <apex:column > <apex:facet name="header">Date Invite Materials Sent to PIE/CAL</apex:facet> <apex:outputText value="{!c.contactlist.Date_Invite_Materials_Sent_to_PIE_CAL__c}"/> </apex:column> <apex:column > <apex:facet name="header">Organisation Name</apex:facet> <apex:outputText value="{!c.contactlist.Account.Name}"/> </apex:column> <apex:column > <apex:facet name="header">Full Name</apex:facet> <apex:outputText value="{!c.contactlist.Name}"/> </apex:column> <apex:column > <apex:facet name="header">Title (Abbreviation)</apex:facet> <apex:outputText value="{!c.contactlist.Title_Full__c}"/> </apex:column> <apex:column > <apex:facet name="header">Operating Group</apex:facet> <apex:outputText value="{!c.contactlist.Account.Operating_Group__c}"/> </apex:column> <apex:column > <apex:facet name="header">Industry</apex:facet> <apex:outputText value="{!c.contactlist.Account.Industry}"/> </apex:column> <apex:column > <apex:facet name="header">Client Classification</apex:facet> <apex:outputText value="{!c.contactlist.Account.Client_Classification__c}"/> </apex:column> <apex:column > <apex:facet name="header">Client Account Lead</apex:facet> <apex:outputText value="{!c.contactlist.Client_Account_Lead__c}"/> </apex:column> <apex:column > <apex:facet name="header">Marketing Contacts</apex:facet> <apex:outputText value="{!c.contactlist.Marketing_OG_Lead__c}"/> </apex:column> <apex:column > <apex:facet name="header">Region</apex:facet> <apex:outputText value="{!c.contactlist.Region__c}"/> </apex:column> <apex:column > <apex:facet name="header">Point of Contact (POC)</apex:facet> <apex:outputText value="{!c.contactlist.Point_of_Contact__c}"/> </apex:column> <apex:column > <apex:facet name="header">Management Link</apex:facet> <apex:outputText value="{!c.contactlist.Management_Link__c}"/> </apex:column> <apex:column > <apex:facet name="header">Revenues (Mil) Value</apex:facet> <apex:outputText value="{!c.contactlist.Account.Revenues_Mil_Value__c}"/> </apex:column> <apex:column > <apex:facet name="header">Comments</apex:facet> <apex: value="{!c.contactlist.h_All_Feedback_Comments__c}"/> </apex:column> </apex:dataTable> </apex:pageBlock></apex:form></apex:page>

public class dataTableContacts {private final String project;public Transient List<cContact> contactlist {get; set;} public dataTableContacts() { project = ApexPages.currentPage().getParameters().get('String'); System.debug('project: '+project); } public List<cContact> getContacts() { if (contactlist == null){ contactlist = new List<cContact>(); for (Contact c : [SELECT Id, Name, Region__c, Member__c, Member_Source__c, Client_Account_Lead__c, Title_Full__c, Project__c, Management_Link__c, Marketing_OG_Lead__c, Marketing_Contacts__c, Point_of_Contact__c, Date_of_CAL_Approval__c, Date_Invite_Materials_Sent_to_PIE_CAL__c, Account.Name, Account.Industry, Account.Operating_Group__c, Account.Revenues_Mil_Value__c, Account.Client_Classification__c , h_All_Feedback_Comments__c, (SELECT Id, Name, Organisation__c, Title__c, Date_of_Interview__c, Project__c, Comments__c, Points_Received__c, Points_Possible__c, Percent__c, Interview_Status__c, Interview_Conducted_By__c FROM New_Member_Interview__r) FROM Contact WHERE Project__c = :project limit 1000]){ contactlist.add(new cContact(c)); System.debug('contactlist: '+contactlist); } } return contactlist; } public class cContact{ public Contact contactlist {get; set;} public cContact(Contact c){ contactlist = c; } }}

 

 

 

RudiHulsbosRudiHulsbos

Not sure what happened to the code spacing, here it is again:

 

 

 

 

public class dataTableContacts {

private final String project;

public Transient List<cContact> contactlist {get; set;}

 

  public dataTableContacts() {

     

         project = ApexPages.currentPage().getParameters().get('String'); 

         System.debug('project: '+project);

  }

                        

  public List<cContact> getContacts() {

         if (contactlist == null){

             contactlist = new List<cContact>();

              

             for (Contact c : [SELECT Id, Name, Region__c, Member__c, Member_Source__c,

                               Client_Account_Lead__c, Title_Full__c, Project__c, Management_Link__c,

                               Marketing_OG_Lead__c, Marketing_Contacts__c, Point_of_Contact__c, Date_of_CAL_Approval__c,

                               Date_Invite_Materials_Sent_to_PIE_CAL__c, Account.Name, Account.Industry, 

                               Account.Operating_Group__c, Account.Revenues_Mil_Value__c, Account.Client_Classification__c ,

                               h_All_Feedback_Comments__c, (SELECT Id, Name, Organisation__c, Title__c, Date_of_Interview__c, 

                               Project__c, Comments__c, Points_Received__c, Points_Possible__c, Percent__c, Interview_Status__c, 

                               Interview_Conducted_By__c FROM New_Member_Interview__r) 

                               FROM Contact WHERE Project__c = :project limit 1000]){

                               contactlist.add(new cContact(c));

                               System.debug('contactlist: '+contactlist); 

             }

         

         }

  return contactlist;

  }

  

  public class cContact{

      public Contact contactlist {get; set;}    

  

      public cContact(Contact c){

            contactlist = c;

            }

  }

}

 

JimRaeJimRae

Looks like you are already passing the child dataset into your wrapper inside of the  contact object.

Is your question how to expose it? The way you have your query written you have a list inside your list.

That is, each contact you return could have 0 or more of the  New_Member_Interview objects attached to it.

 

So, if you know there would only be one for each, you could add a limit 1 to that part of the query, and then reference the fields directly on your VF page.

 

Looks like your var is "c" when you iterate the wrapper class, and your contacts are all called contactlist

 

So you have {!c.contactlist.name} for the contact name (for example),

To get to the next level, you would use something like {!c.contactlist.New_Member_Interview__c.name} to get to the next level.


If you expect multiple values, you might look into using the repeat tag to display the data, with a nested repeat inside.

 

 

RudiHulsbosRudiHulsbos

Hi Jim,

 

Thanks for the reply, i tried your suggestion but i get the following error:

 

 

 

Error: Invalid field New_Member_Interview__c for SObject Contact

 

Here is my visualforce code:

 

<apex:column >

           <apex:facet name="header">Date of Interview</apex:facet>

           <apex:outputText value="{!c.contactlist.New_Member_Interview__c.Date_of_Interview__c}"/> 

</apex:column>

 

How do i resolve this?

 

Thanks,

 

Rudi 

 

JimRaeJimRae

Maybe it should be:

 

 

<apex:column > <apex:facet name="header">Date of Interview</apex:facet> <apex:robotsurprised:utputText value="{!c.contactlist.New_Member_Interview__r.Date_of_Interview__c}"/> </apex:column>