1

Currently I have code that uses apex:repeat to push out nested data from a custom object and I need to add the chatter for the ParentObject to the output. I've been trying to find a way to do this by adding another nested query node to my full query but I can't figure out how to nest queries for FeedItem or ParentObject__Feed. I am open to doing this another way, but need some guidance.

Original Code:

    //CONTROLLER CODE
    List<ParentObject__c> parent_objects = [SELECT Id, Name, (Select Id, Name From ChildObject1s__r), (Select Id, Name From ChildObject2s__r) From ParentObject__c];

    //VF PAGE CODE
    <apex:repeat value="{!parent_objects}" var="parent">
        {!parent.Name}
        <apex:repeat value="{!parent.ChildObject1s__r}" var="child1">
            {!child1.Name}
        </apex:repeat>
        <apex:repeat value="{!parent.ChildObject2s__r}" var="child2">
            {!child2.Name}
        </apex:repeat>
    </apex:repeat>

Most Recent Failed Attempt:

    //CONTROLLER CODE
    List<ParentObject__c> parent_objects = [SELECT Id, Name, (Select Id, Name From ChildObject1s__r), (Select Id, Name From ChildObject2s__r), (Select Body From FeedItems) From ParentObject__c];

    //VF PAGE CODE
    <apex:repeat value="{!parent_objects}" var="parent">
        {!parent.Name}
        <apex:repeat value="{!parent.ChildObject1s__r}" var="child1">
            {!child1.Name}
        </apex:repeat>
        <apex:repeat value="{!parent.ChildObject2s__r}" var="child2">
            {!child2.Name}
        </apex:repeat>
         <apex:repeat value="{!parent.FeedITems}" var="feed">
            {!feed.body}
        </apex:repeat>
    </apex:repeat>
3

So it's possible to get the Feeds child-relationship in the query. Use the SOQL query builder in the Force.com IDE to figure out the shape of the available queries:

Select p.Name, (Select Id, ParentId, Type, CommentCount, LikeCount, Title, Body, LinkUrl, RelatedRecordId, ContentData, ContentFileName, ContentDescription, ContentType, ContentSize, InsertedById From Feeds) From Project_Task__c p

In the case of custom objects, the name of the child-relationship is: Feeds some standard objects have their own names, like AccountFeed on Account

Than you can output them like you talked about above, try:

<apex:repeat value="{!parent_objects}" var="parent">
        {!parent.Name}
        <apex:repeat value="{!parent.Feeds}" var="feedItem">
            {!feedItem.body}
        </apex:repeat>
    </apex:repeat>
1
  • Ah! I was using FeedItems not Feeds. Gotcha. Thanks. – Matthew Whittemore Oct 10 '12 at 18:28

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.