Find your content:

Search form

You are here

Query Chatter as part of nested query on a custom object

 
Share

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>

Attribution to: mcwhittemore

Possible Suggestion/Solution #1

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>

Attribution to: jordan.baucke
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/2103

My Block Status

My Block Content