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
Malakai LaviMalakai Lavi 

Like a chatter post

I wrote a chatter bot that creates a feed item when a certain action takes place.
I want to write code that will "like" certain posts when they are posted.
I would like to do this using an apex class. What is the code that adds a "like" to a feed post?
SarfarajSarfaraj
Hi Malakai

This is the rest resource to like,
/services/data/<api-version>/chatter/feed-items/<feed-item-id>/likes
Method is POST

And this is to unlike,
/services/data/<api-version>/chatter/likes/<like-id>
Method DELETE

Get all likes to a feed-item,

/services/data/<api-version>/chatter/feed-items/<feed-item-id>/likes
Method is GET.

--Akram
Malakai LaviMalakai Lavi
Hi Akram,

Can you give an example of how to use this in an Apex class? I am not familiar with rest.
alouie_sfdcalouie_sfdc
See the ConnectApi.ChatterFeeds.likeFeedElement() and ConnectApi.ChatterFeeds.likeComment() methods in the Apex documentation:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_ConnectAPI_ChatterFeeds_static_methods.htm#apex_ConnectAPI_ChatterFeeds_static_methods