0

I use a code like this:

<apex:page standardController="Account" showHeader="false" >   
          <apex:repeat value="{!Account.Tasks}" var="task">
               <apex:outputField value="{!task.Owner.Name}"/>
                     ...

in a visualforce page to iterate through the tasks of the account currently viewed. It works, but it ignores Tasks of an Opportunity related to the Account. These should also be shown.

Essentially the same Task-list as on the native activity view should be shown.

Is there a simple way to make this work with my existing code? I tried traversing it with something like {!Account.Opportunity.Task}, but that didn't work.

1

It does not seems to be possible to achieve this with Standardcontroller you have to go for custom controller.

I tried to use aggregate relation like this

<apex:page standardController="Account" showHeader="false" >   
    <apex:repeat value="{!Account.Tasks}" var="task">
        <apex:outputField value="{!task.Owner.Name}"/>,
        <apex:outputField value="{!task.Subject}"/>
        <apex:repeat value="{!Account.Opportunities}" var="opp">
            <apex:repeat value="{!opp.Tasks}" var="task">
                <apex:outputField value="{!task.Owner.Name}"/>,
                <apex:outputField value="{!task.Subject}"/>
            </apex:repeat>
        </apex:repeat>
    </apex:repeat>
</apex:page>

But in background standardcontroller is building 2 level aggregate query which is not allowed. While saving it throws an error.

"SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.. Original queryString was: 'SELECT Id, (SELECT Id, (SELECT Id, Owner.Name, Subject FROM Tasks) FROM Opportunities), (SELECT Id, Owner.Name, Subject FROM Tasks) FROM Account WHERE id = '000000000000000'' Error Error: SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object."

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.