[SalesForce] Render item from related list on Visualforce Page

I'm trying to render an item from one related list on PDF. the structure is following:
I have Sales Order, where is lookup field to Company, on Company is related list of Bank Accounts which I need to render. The Bank Accounts are related to Company through lookup, not master-detail. Here is code which I'm using:

<apex:repeat value="{!salesInvoice.c2g__OwnerCompany__r.c2g__BankAccounts__r}" var="account">  
<apex:outputText value="{!account.c2g__AccountName__c}" rendered="true" escape="false"/>
</apex:repeat>

But get an error:

Error: Aggregate Relationship is used in an unsupported complex
expression containing 'c2g__OwnerCompany__r.c2g__bankaccounts__r'

Any ideas?

Best Answer

You cannot bind two levels down child relationships.

Your apex:repeat binding looks like this:

salesInvoice.c2g__OwnerCompany__r.c2g__BankAccounts__r

The problem is that c2g__OwnerCompany__r is a list. But you're trying to tell the interator to bind to a list within a list: c2g__OwnerCompany__r.c2g__BankAccounts__r.

This is not allowed.

In theory you could do something like:

<apex:repeat value="{!salesInvoice.c2g__OwnerCompany__r}" var="ownerCompany">  
  <apex:repeat value="{!ownerCompany.c2G__BankAccounts__r}" var="account">
    <apex:outputText value="{!account.c2g__AccountName__c}" rendered="true" escape="false"/>
  </apex:repeat>
</apex:repeat>

This would give you the ability to list all children of children.

Related Topic