You need to sign in to do that
Don't have an account?

Chatter Subquery doesn't return related comments
I have a query where I'm trying to return the chatter posts and comments that pertain to a specific set of sObject's that were previously queried:
List<sObject__c> items = [SELECT Id FROM sObject__c ...]; Map<Id,sObject__Feed> projectTaskFeeds = new Map<Id,Project_Task__Feed>([SELECT Id, Type, CreatedById, CreatedBy.FirstName, CreatedBy.LastName, ParentId, Parent.Name, Body, Title, LinkUrl, ContentData, ContentFileName, (SELECT Id, CommentBody, CreatedDate, CreatedBy.FirstName, CreatedBy.LastName FROM FeedComments) FROM sObject__Feed WHERE ParentId IN :items LIMIT 50000]);
But the resulting map only contains the sObject__c feed items, and not the related FeedComments.
Map<Id,sObject__Feed> projectTaskFeeds = new Map<Id,Project_Task__Feed>([SELECT Id, Type, CreatedById, CreatedBy.FirstName, CreatedBy.LastName, ParentId, Parent.Name, Body, Title, LinkUrl, ContentData, ContentFileName, (SELECT Id, CommentBody, CreatedDate, CreatedBy.FirstName, CreatedBy.LastName FROM FeedComments) FROM sObject__Feed LIMIT 50000]);
If I don't use the limiting 'WHERE' Clause however, I get the comments as well (but I got all items that are in the sObject__Feed table, which could easily be more than 50000 results in a large org.
Am I doing something wrong?
Use the AccountFeed for example, just create some feed and comment on some Account,...
try the code below:
Map<Id, AccountFeed> mapaccfeed = new Map<Id, AccountFeed>([Select Id, Body, (Select Id, CommentBody, CreatedDate From FeedComments) From AccountFeed Where CommentCount > 0 Order by CreatedDate Desc Limit 10]);
System.debug(' ----------- ' + mapaccfeed);
Set<Id> idset = mapaccfeed.keyset();
for(Id aid : idset) {
List<FeedComment> fclist = (mapaccfeed.get(aid)).FeedComments;
for(FeedComment fc : fclist) {
System.debug(' ------------ ' + fc.CommentBody + ' ' + fc.CreatedDate );
}
}
You will see your Comment input now,...
Use CommentCount > 0 to query the Feed with Comment for demo,...
All Answers
Did you try querying FeedItem table instead of sObject__Feed?
Actually, just reopened my debugger window and it started working...
Don't know if it works consistently yet but I think it was something in the debugger window!
Use the AccountFeed for example, just create some feed and comment on some Account,...
try the code below:
Map<Id, AccountFeed> mapaccfeed = new Map<Id, AccountFeed>([Select Id, Body, (Select Id, CommentBody, CreatedDate From FeedComments) From AccountFeed Where CommentCount > 0 Order by CreatedDate Desc Limit 10]);
System.debug(' ----------- ' + mapaccfeed);
Set<Id> idset = mapaccfeed.keyset();
for(Id aid : idset) {
List<FeedComment> fclist = (mapaccfeed.get(aid)).FeedComments;
for(FeedComment fc : fclist) {
System.debug(' ------------ ' + fc.CommentBody + ' ' + fc.CreatedDate );
}
}
You will see your Comment input now,...
Use CommentCount > 0 to query the Feed with Comment for demo,...
Ultimately I found that I was recieving an error in the debugging window. When I ran the chatter reciepe code, it ran normally in another org.
There was no error message. It simply did not show the results in the debugging log.