function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
stunaitestunaite 

Getting FeedLikes return an exception: Aggregate query has too many rows for direct assignment

Hi,

 

I am trying to populate a list with all likes from a chatter feedItem

 

This is the query (pay attention that FeedLike can't be queried directly so using a subquery is the only way... as much as I know):

 

List<feeditem> feedItemLst = [select likeCount,(select feedItemid, feedEntityId from feedlikes) FROM feeditem WHERE likecount > 0

 

List<feedLike> feedLikeLst = new List<feedLike>();
for(FeedItem feeditemcr:feeditemLst){
    for(FeedLike feedlikecr: feeditemcr.feedlikes){ //results in an exception Aggregate query has too many rows for direct assignment, use FOR loop
        feedLikeLst.add(feedlikecr);
}
}

 

so I replace by:

 

List<feedLike> feedLikeLst = new List<feedLike>();
for(FeedItem feeditemcr:feeditemLst){
    for(sObject feedlikecr: feeditemcr.getsObjects('FeedLikes')){ //Returns a list with just 1 feedlike ignoring the remaining ones
        feedLikeLst.add((FeedLike)fl); 
    }
}

 

Does someone have an idea to overtake this?

 

Many Thanks in Advance

 

Joao