Followed Records List in Lightning Using Flow

Followed Records List in Lightning Using Flow

You can follow records to see updates in your feed, including field changes, posts, tasks, and comments. The field changes that you see in your feed depend on the fields that were enabled for feed tracking. You can follow a maximum combined total of 500 people, topics, and records.

You can follow a record by clicking on the Follow button. It is also possible to auto-follow the records that you create by navigating to My Feeds under your settings and marking the checkbox called Automatically follow records I create.

To stop following a record on the record page, click again the same button (button's label changes to Unfollow).

In Lightning Experience, what you see after clicking the Follow button depends on whether streams are enabled. If there are available streams in the org, it will display you the stream choices. You can add the record to an existing or a new stream. Chatter streams are custom feeds that you create by combining multiple related feeds into one feed. You can find streams in Lightning Experience on the Chatter page.

You can see all the records that you added to a stream by navigating to the Streams home page.

Even though it is a way to see all of them together, it doesn't show enough information about the records. On the other hand, it displays only the records from a stream, it doesn't display all the records that you follow. Lets assume that you are not using streams and you just follow records.

Where Are The Records That I Follow?

It is a great feature for sure, but after following many records, you forget what you follow. There should be a way to see a list of records that you follow. So that you can decide to unfollow or keep following them according to their details.

In Salesforce Classic, there is a part called "Following" on User Profile page. Even though it doesn't display enough information, at least you can see all the records that you follow.

However, Following list doesn't exist in Salesforce Lightning. In Lightning Experience, only the people who you follow and who are following you appear on your profile.

When you follow a record, Salesforce stores this information in a table/object called EntitySubscription. This object has only a few fields. ParentId is the record Id that a user follows, SubscriberId is the user's Id and CreatedDate is the date/time that the user started following the record.

Okay, so at least there is an object that stores all of this information. However, it doesn't store enough information from those records (for example the status and the subject of a case) and also it is not an object that is available on the UI. So, you cannot create a list view.

Using Flow to Create a List

Since Flow can query almost any object, it possible to build a Screen Flow that displays the records that current user follows. It can be done by using the standard elements of Flow, but to make it look and perform better, I recommend you to use some custom components/actions.

Lets create a Screen Flow that displays the Case records that a user follows.

As mentioned above, EntitySubscription stores the record's and user's Id. It is not enough to display those records to the user. Because of this, we have to display the case records that exist in that table. So it means that we have to use a sub query.

It is possible to get the relevant EntitySubscription records and then do a loop to bring the Case records that exist in that list. However, it would be a long flow and we could hit the governor limits.

We would like to run a query like this;

Select CaseNumber, Status from Case Where Id IN (Select ParentId From EntitySubscription)

Lets see how to create a Screen Flow that displays the case records that the current user follows.

1- Create a Screen Flow. If you don't know what Screen Flow is or want to learn more about it, you can read this post.

2- To avoid hitting the limits and make the Flow perform better/faster, I recommend you to use a custom Apex Action that can be found on UnofficialSf. There is an Apex Action called Execute SOQL Query that lets you execute a query. At the end, it stores the results in a collection.

3- Create a Text Template and store the query in it. We want to display the case records that the current user follows, so you have to filter the records.

You can enter a query like this. Change the filters or fields that you want to display according to your needs.

Pay attention that EntitySubscription records are filtered by the current user.

Select Id, CaseNumber, Subject, Status From Case Where Id IN (Select ParentId From EntitySubscription Where SubscriberId='{!$User.Id}')

4- Drag and drop the action element from the toolbox and select Execute SOQL Query action that you installed. Select the object (in this example it is the Case object) and select the text template that you created in the previous step. Create a record collection variable and store the output of the Apex action in it.

5- Optionally, add a Decision element to check if there are records in the collection. If the current user is not following any records, you can display a message instead of a blank table.

6- Display the Case records on a screen. Since we want to display a few fields from the object, I recommend you to use the DataTable component. It can be installed from UnofficialSf. Using this component, you can display the records in a table and make it look like a list view.

Create a screen and drag and drop the custom component that called Datatable (it is the LWC that you installed in the previous step). Give it a name, select the object, select the record collection that you store the records, and do the other configurations of the Datatable (selecting the fields to display, disallowing the row selection, etc.)

7- At the end, your flow should look like this.

In the screen called No Cases, you can display a message that the current user is not following any cases.

This flow is not updating, creating, or deleting records. It just gets records and displays them to the user (like a list view).

After activating the flow, you can put it to any Lightning Page. Like any other list view, users can click on the Case Number to navigate to the record and they can unfollow the record if they want to.

1 Trackback / Pingback

  1. Using Flow to Auto Follow Records - Salesforce Time

Leave a Reply

Your email address will not be published.


*