-2

'm trying display parent fields and sub query fields in a table.But I'm unable to display sub query fields.Could anyone suggest an idea for me

Page : ======

                                    <tr>
                                        <td data-label="Name">
                                            <div class="slds-truncate" >{!c.Name}  </div>
                                        </td>
                                        <td scope="row" data-label="Email">
                                            <div class="slds-truncate" >{!c.Login__c}</div>
                                        </td>
                                        <td data-label="Date">
                                            <div class="slds-truncate" >
                                            <apex:outputfield value="{!c.LastModifiedDate}" />
                                            </div>
                                        </td>
                                        <td data-label="Voucher">
                                            <div class="slds-truncate" >
                                            <apex:outputfield value="{!c.Voucher_Number__c}" />
                                            </div>
                                        </td>
                                        <td data-label="Email Sent">
                                            <div class="slds-truncate" >
                                            <apex:outputfield value="{!c.Email_Sent__c}" />
                                            </div>
                                        </td>  
                                          <td data-label="Voucher Assign Date">
                                            <div class="slds-truncate" >
                                            <apex:outputfield value="{!c.Voucher_Assign_Date__c}" />
                                            </div>
                                        </td> 

                                    </tr>

controller :

 public List<Webinar_Attendees__c> getMyResult(){

     list<String> t = new list<String>();
     list<Webinar_Attendees__c> re = [SELECT Id,Login__c,Name,Opportunity__c,WebinarContact__c,Voucher_Number__c,Email_Sent__c, LastModifiedDate,(select Id,Name,Voucher_Assign_Date__c from Voucher_Repository__r  )
                                     FROM Webinar_Attendees__c WHERE Voucher_Number__c != Null AND CreatedDate <= TODAY 
                                     ORDER BY LastModifiedDate DESC NULLS FIRST LIMIT : limitsize OFFSET : count];   


     for(Webinar_Attendees__c web : re){

         for(Voucher_Repository__c rep : web.Voucher_Repository__r){

            Date dateField = rep.Voucher_Assign_Date__c;
            String strDate = string.valueOfGmt(dateField);  

         }
     }

    return re ;    
 } 
1

The field Voucher_Assign_Date__c seems to belong to the object Voucher_Repository__c and not to the object Webinar_Attendees__c.

In your VF page, it looks like the variable c is assigned to an object of type Webinar_Attendees__c, not of type Webinar_Attendees__c.

So, there are two potential issues here.

  1. There is a field called Voucher_Assign_Date__c in the object Voucher_Repository__c and you're not querying for it (you're querying the one belonging to the other object, Webinar_Attendees__c)

    OR

  2. You're querying the right field but referring to it incorrectly. If this is the case, you should do in your VF something similar to what is done in your apex. Iterate (another apex:repeat) on the Voucher_Repository__r collection and print the field from there instead. As Voucher_Repository__r is a child object of Webinar_Attendees__c, be aware that you may encounter more than one record and thus you may display that value more than once. Be sure to adjust your UX accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.