0

I have 2 objects Agreement__c(Parent) and section__c(child) with a relationship name Agreement_Section. I'm trying to build a pdf with datatable iterate of child records but not able to relate the objects and getting the error 'Invalid field name Title__c'.

Here is my code:

Vf page:

 <table width="100%" class="table-bordered">
        <thead>
            <tr>
                <th> Title</th>
                <th> Summary </th>
                <th> sample score</th>
                <th> sample  Percentage </th>

            </tr>
        </thead>
        <tbody>
           <apex:repeat value="{!Agreementrecords.Agreement_section__r}" var="a">

                    <tr>
                        <td><apex:outputText value="{!a.Title__c}"/></td>
                        <td><apex:outputText value="{!a.summary__c}"/></td>
                        <td><apex:outputText value="{!a.sample_score__c}"/></td>
                        <td><apex:outputText value="{!a.sample_Percentage__c}"/></td>

                    </tr>
          </apex:repeat>  
        </tbody>
    </table>

Apex Controller:

public List<Review_by_Agency__c> getAgreementrecords(){
List<Agreement__c> Agreementrecords = [Select Name, (select Id, Name,   Title__c,
                                              summary__c,sample_Score__c,sample_percentage__c 
                                               from Agreement_Sections__r) from Agreement__c where ID= :RecordID];
return Agreementrecords;
}
3

The name of the collection that the repeat iterates over needs to be the same name that appears in the relationship query in the controller. Also there are two collections: the collection of Agreement__c and each of those can have a collection of Agreement_Section__c so two repeats are needed. (You will need to experiment on how you want to present those: one table as show below or multiple tables.)

<apex:repeat value="{!Agreementrecords}" var="a">
    <apex:repeat value="{!a.Agreement_Sections__r}" var="s">
        <tr>
           <td><apex:outputText value="{!a.Name}"/></td>
           <td><apex:outputText value="{!s.Title__c}"/></td>
           <td><apex:outputText value="{!s.summary__c}"/></td>
           <td><apex:outputText value="{!s.sample_score__c}"/></td>
           <td><apex:outputText value="{!s.sample_Percentage__c}"/></td>
        </tr>
    </apex:repeat>
</apex:repeat>

(I'm assuming here that the controller does compile meaning that the query has been verified by the Apex compiler.)

  • Getting error like 'Error: Unknown property 'VisualforceArrayList.Agreement_Sections__r' I made sure all collection is similar – Salesforce Learner Mar 19 '16 at 12:44
  • @SalesforceLearner I'd missed that there are two collections - see updated answer. – Keith C Mar 19 '16 at 13:30

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.