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
Matt HimeMatt Hime 

Counting feedcomment likes

Salesforce can give an accurate count of likes for feeditems and feedcomments,  but,  there does not seem to be a way to gather this information programmatically.  I can get a count of likes on feeditem because it's rolled up onto the feeditem record or I can use the feedlike table in a sub-query and count the rows returned.  However,  I cannot do the same for feedcomment.  How are Salesforce doing it?
Best Answer chosen by Matt Hime
Matt HimeMatt Hime
Solved it!  You need to use the ConnectAPI
 
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;

 

All Answers

Shailendra Singh ParmarShailendra Singh Parmar
You can use FeedLike object. it has 2 property FeedItem and FeedEntityId which is Feed comments if use likes feed comments. Follow below document link.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_feedlike.htm

Thanks
Shailendra
Matt HimeMatt Hime
Last line of that document reads,

"...Likes on comments can’t be queried via the API..."
Matt HimeMatt Hime
Solved it!  You need to use the ConnectAPI
 
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;

 
This was selected as the best answer
anju N 1anju N 1
Can any one suggest " Query to get likes on comments "