I've been implementing a chatter integration that enables to like a custom object record from apex.

I've created 1 custom object that represents Articles. Articles have Title, Description, Thumbnail and an access url.

I've enabled Chatter tracking feeds on these objects. And i would like to display a like button on each article listed from a lightning custom component. This like button should behave as the native Chatter Like Button. So i should also be able to query the total likes on each article from Apex.

My code to implement the Custom Chatter Like button using Chatter Apex is as below :

ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), recordId, ConnectApi.FeedElementType.FeedItem, 'hello');
ConnectApi.ChatterLike chatterLike = ConnectApi.ChatterFeeds.likeFeedElement(null, feedElement.Id);

I'm not sure if i'm doing it right, specially the way i create the FeedElement using postFeedElement function.

Have you guys ever done this before? Could you please advice?

Thank you!

  • Are you asking because you're observing some error or non-expected behavior? If so, what is that error?
    – David Reed
    Commented Sep 3, 2018 at 17:44
  • I'm not getting any error , but i'm just wondering if i'm creating the FeedElement as it should be. I'm suprised that to like a record, i've to post a feedElement with a text parameter for example (ie: Hello)
    – Bryce
    Commented Sep 3, 2018 at 17:49
  • Chatter likes apply to feed items, not records. The ERD diagram might be useful (note that AccountFeed is holding the place of the generic FeedItem in the diagram).
    – David Reed
    Commented Sep 3, 2018 at 17:52
  • Great!! So, instead of creating a feedElement, i should create a feedItem with type Record, am i right?
    – Bryce
    Commented Sep 3, 2018 at 17:59
  • It might be helpful if you could add more narrative description (or even screenshots) to your question of what you want the outcome to look like.
    – David Reed
    Commented Sep 3, 2018 at 18:02

1 Answer 1


I think you may be looking for "follow" functionality. If so you should be able to execute DML operations on the EntitySubscription object directly, with no need for the ConnectAPI.


Represents a subscription for a user following a record or another user. This object is available in API version 34.0 and later.

A user can subscribe to a record or to another user. Changes to the record and updates from the users are displayed in the Chatter feed on the user's home page, which is a useful way to stay up-to-date with other users and with changes made to records in Salesforce. Feeds are available in API version 18.0 and later.

If you look at other Chatter Objects, most others support DML as well. The only time I've found the ConnectAPI necessary is when you want to generate a FeedItem via Apex whose body contains an @mention.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .