+ Start a Discussion
Chirag MehtaChirag Mehta 

SOQL for fetching CommentLikes

Hi,

 

I have requirement to fetch comment likes. I'm not able to figure out on how to retrieve commentlikes.

 

FeedLike object represents likes. You can't query FeedLike records directly. They can only be queried via the parent NewsFeedUserProfileFeed, or entity feed, such as AccountFeed.

 

So to query FeedPost likes, use following:

SELECT Id, (SELECT Id, CreatedById, CreatedDate, FeedItemId, FeedEntityId FROM FeedLikes) FROM UserFeed

 

to query group post likes, use following:

SELECT Id, (SELECT Id, CreatedById, CreatedDate, FeedItemId, FeedEntityId FROM FeedLikes) FROM CollaborationGroupFeed

 

How to retrieve comment likes?

 

 

ChrisOctagonChrisOctagon

I think the only way you can fetch likes on comments is through the Chatter REST API: http://developer.force.com/chatter-api

Chirag MehtaChirag Mehta

That's bad :((

 

@Chris - Thanks for sharing the info.

 

 

Chirag MehtaChirag Mehta

But the only problem with using chatter REST API for fetching comment like is that - it needs particular commentid. In such a case, we might end up in querying all comments and then making one call at a time to fetch whether that comment is liked or not. This is not a scalable approach in terms of determining entire org comment likes.

ChrisOctagonChrisOctagon

Ya it sounds like in this case it is a bit awkward. By the way, it is possible to get likes for many comments in a feed at once: when you retrieve a specific feed through the Chatter REST API, you receive a page of feed items and each of those feed items includes a page of comments and each comment includes a page of likes.

LoganLogan

Could you describe your use case?  Exactly what data do you need to retrieve? (just getting a like seems pretty useless if you don' t know what its parent object is)  How much of it do you need to retrieve, what are you going to do with it, how often are you retrieving it...

Ashish_NarangAshish_Narang
Even I have same issue, What we are trying to do is:
We have a custom object on which feed is enabled and trying to migrate such custom object to another custom object. We are able to migrate FeedItem and its likes along with FeedComment but not able to migrate Likes on FeedComment. So we are kind of stuck, not able to find a way to migrate CommentLikes.
jagjit Singh 17jagjit Singh 17
One can make use of ConnectApi to fetch feedlikes info. It is possible and I have implemented it.
Akash M DAkash M D
@jagjit Singh - Can you explain a little how you can extract all the likes on comments/Posts in a batch way?
SwethaSwetha (Salesforce Developers) 
@Akash M D You might want to try something like this
 
id yourFeedCommentId = [select id from FeedComment limit 1].id;
id yourCommunityId = [select id from Network where Status = 'Live' limit 1].Id;

ConnectApi.ChatterLikePage clp = ConnectApi.ChatterFeeds.getLikesForComment(yourCommunityId, yourFeedCommentId);

integer likeCount = clp.total;