Home SalesforceApex Generate Topic Followers List

Generate Topic Followers List

by Dhanik Lal Sahni
Salesforce Topic List

Salesforce Topics are phrases that we can associate with Salesforce records to organize them around common themes. This is similar to hashtag (#) given on social media platforms like Twitter and LinkedIn. We associate hashtags to associate posts with similar topics or groups.

Similarly, we can associate topics with any Salesforce records to provide connections across people, conversations, and records. This will also help us in searching similar records very easily. Users can follow these topics to get the latest information about them. Right now we can not add a tab for a Topic object so we can not generate a list of all topics and their followers. This post will help to generate a Topic followers list.

Solution:

  1. Create Apex code to prepare topics and their followers
  2. Create LWC to show the topic followers list
  3. Demo

1. Create Apex to prepare topics and their followers

We can get a list of all topics using the Topic object. When we follow any topic then one record is created in EntitySubscription object. We will get Topic Subscribers for each topic from EntitySubscription object. Let us create apex classes for getting the list of all topics with its followers.

2. Create LWC to show the topic followers list

Let us create a Lightning Web Component to show the list of all topics and their followers. We will use lightning-tree-grid control to show the topic list in a hierarchical grid. lightning-tree-grid need _children attribute for each parent to show as a child list so have to add that property in the returned result.

let recs = JSON.parse(JSON.stringify(data));
//add new property _children for each records
recs.forEach(function(obj) {
       obj._children = obj['followers'];
});

Complete LWC Code:

3. Demo Page:

Add the above created LWC component on the lightning tab, record page, or home page to show topics and followers list.

References:

Tree Grid

Salesforce Topics for Object

Posting Rich Text Chatter using Apex

You may also like

1 comment

Post Chatter Feed Using FeedItem in Flow - SalesforceCodex June 12, 2023 - 9:49 am

[…] Generate Topic Followers List […]

Reply

Leave a Comment