0
votes

I have a visualforce page with the standardController to a custom object. I want to get all orders (Orders__c) from an event (Event__c). I started by the offer (Offer__c)

Offer is in master-detail with the event and the event is in master-detail with the orders.

I have tried two following codes:

<apex:page standardController="Caterer_Offer__c" sidebar="false" showHeader="false" >
<apex:repeat var="events" value="{!Caterer_Offer__c.Event__r}">
    {!events.Name}
    <apex:repeat var="orders" value="{!events.Orders__r}">
        <!-- {!orders.Name}-->
    </apex:repeat>
</apex:repeat>

At this the error-message in the developer console is:

"Aggregate Relationship is used in an unsupported complex expression containing 'Event__r.orders__r'"

And...then I have trief to save the event and use a new variable to "repeat" all orders. I get no error message, but a error in Salesforce

<apex:page standardController="Caterer_Offer__c" sidebar="false" showHeader="false" >
<apex:repeat var="events" value="{!Caterer_Offer__c.Event__r}">
    {!events.Name}
    <apex:variable var="e" value="{!events}"/>
    <apex:repeat var="orders" value="{!e.Orders__r}">
        <!-- {!orders.Name}-->
    </apex:repeat>
</apex:repeat>

Error-message: SObject row was retrieved via SOQL without querying the requested field: Event__c.Orders__r

I cannot explain it and work on it since a few hours....

2

2 Answers

0
votes

A standardcontroller's record will only contain the fields referenced in the visualforce page you're using it on. You may need to use a custom controller and extend features of standard controller in these cases. The standard controller addFields() method allows you to extend this to the fields you need in your apex code.

I could find a similar solution here.

0
votes

I'm not sure from your question which object is the Parent record and which is the child, but my answer is going to be based on Caterer_Offer__c being the parent of Event__c and Event__c being the parent of Order__c, so that you can loop through all Orders for an Event for a Catered Offer which is what I think you want to do.

In short what you are trying to do cannot be done in the way you are trying it is because you are in essence trying to perform a child aggregate query that is two levels deep. In essence you are trying to do:

[SELECT Name, (SELECT Name, (SELECT Name FROM Orders__r) FROM Events__r) FROM Caterer_Offer__c];

However salesforce only allows aggregate child queries one level deep, not more. So you have to add an extension that would have code to probably lazy-load the Orders on an event of some sort with a partial page re-render on a link click or button click. In that case you would make the Visualforce page for the Caterer_Offer__c and child Events__c, then load the child Orders from some user action that calls the extension with a element using the id of the selected Event.

But for the error you specifically asked about it would have been:

<apex:page standardController="Caterer_Offer__c" sidebar="false" showHeader="false" >
    <apex:repeat var="event" value="{!Caterer_Offer__c.Events__r}">
        {!event.Name}
        <apex:repeat var="order" value="{!event.Orders__r}">
            {!order.Name}
        </apex:repeat>
    </apex:repeat>
</apex:page>

But again that's not possible because of the aforementioned single depth child aggregation query limitation in salesforce