Auto Follow New Users In Chatter

In Salesforce Chatter is a great way to boost internal Collaboration. This is great because it allows your organization to keep all its data and information in one place. A user can Post Status, link, File, and comment on others post etc. Many time I found on success community people are asking about a way to Auto follow a new user. The first solution that comes upon in our mind is to write an Apex Trigger, but do you know you can achieve the same functionality without using code i.e. by using Flow and Workflow Rule to fire/trigger our Flow. Few benefits of following the new user is

1) Keep up with what new user are doing by following and you can able to guide them so they will get more out of it.
2) You can help them to improve their productivity by clearing their doubts because after following you can track their Chatter activity.

Business Use Case

Higher management in Universal Container wants to develop an application for their organization so that new users will auto follow by all System administrators.

Solution for the above business requirement

To solve this requirement we will use Flow and Headless Flow. Before going ahead with the solution you have to understand about EntitySubscriptionObject. It’s Represents a subscription for a user following a record or another user. The user can subscribe to a record or to another user.

Field Name

Details

ParentId

ID of the record or user which the user is following

SubscriberId

ID of the User who is following the record or user

To develop this application follow the below instructions

1) Create a Custom Field Start(Data Type: – Check-box) on the Userobject. We will use this field in Workflow Rule.
2) Click on Name | Setup | App Setup | Create | Workflows & Approvals | Flows
3) Click on New Flow, it will open flow canvas for you. Now create One Text type variable ParentID (To pass the new user ID ),

Variable to store new User ID

4) Drag and drop a Fast Lookup ( Give the name System Administrators UserID) onto the window to get a list of users those having a system administrator profile and and map the fields according to below details

Select Object User

IsActive= TRUE

ProfileId= 00e90000001A75c [System Administrator profile ID], Save the records ID into Sobject Collection variable in our case it’s {!UsersID}, You can take help from the following screenshot

To get Users with profile system administrator

5) Drag and drop a Loop Logic (Give the name Extract user id one by one) on the window to extract value from Sobject Collection variable and pass it to Sobject variable, as shown in the below screenshot

Loop to extract User ID one-by-one

6) Drag and Drop Assignment Logic (Give the name Set follower detail) on the window, to assign SubscriberID and ParentID and into the Sobject variable (EntitySubscription Object Type) {!FollowerDetail}as shown in the below screenshot

Set Follower Details

7) Drag and Drop Assignment Logic (Give the name All Details into one Collection Variable) on the window and assign value from Sobject variable {!FollowerDetail} to Sobject Collection variable {!MassFollow} so at the end of the for loop (To avoid SOQL limit) we will use it inside the Fast Create for Auto follow new users. You can take help from the following screenshot

Bulkify your flow

8) Our final task is to create records in EntitySubscription object, To do that drag and Drop Fast Create (Give the name Auto Follow New Users) on the window and map the field according to the below screenshot

Auto Follow New Users

9) Finally our Flow will look like the following screenshot

10) Save the flow with name Auto Follow New Users and close the canvas.

Create Workflow rule to fire our Flow

Our next task is to create a workflow on the User object on creation and every time it’s edited event. To create a workflow on the User object follow the below instructions

1) Click on Name | Setup | App Setup | Create | Workflows & Approvals | New Rule
2) Select object User from the drop-down
3) Enter Name, for Evaluate the rule when a record is select Created, For Rule Criteria select is Active To True, as shown in the below screenshot

Workflow Rule on User Creation

4) Now Add a time trigger to to set Start To True (Custom field – Checkbox ) after 0 hours of record Creation date. To do this click on Add Time Trigger button and Set the length after how many days/hours workflow will fire i.e. in hours and days, I’ve selected 0 hours after the Created Date. Now add one field update action for time dependent workflow and set the Start to True. You can take help from the following screenshot

Workflow Field Update

5) Save the workflow and activate it.
6) Create another workflow (i.e. workflow Rule2 ) on the same object i.e. User to fire our Flow, set entry criteria of trigger is Start To True

Workflow Rule2

7) Add one Immediate Workflow Actions i.e.New Flow Trigger, Select Flow (Auto Follow New Users) and set Variable (ParentID) value as shown in the following screenshot

New Flow Trigger Action

8) Add one more Immediate Workflow Actions i.e.New Field Update and Set Start to False, so it won’t create an issue next time when you will try to update the user.
9) Save the workflow and activate it.

Note: – I will suggest you Implement this first on your developer org test it and then move it to Production.

Stacey

Is there an updated process to this via process builder? I don’t have an immediate workflow action to launch a flow and I’ve been trying to use Process Builder but can’t get this to work. I think I am entering the wrong flow variables/values in the Set Flow Variables step of process builder.

Is there a way to handle existing follow record errors? I want to create a button where my users can “Follow Everyone” but when I attempt to use your process I am running into the issue of existing duplicate records in EntitySubscription because I am already following some people.

These changes generate a collection that has all users being subscribed to by the user that starts the flow. This works but I can’t get around the issue of existing duplicate records existing in EntitySubscription.

FYI,I don’t have the ability to post files or pics on your blog so typing this out was the only way to go.

You have to modify the Flow to remove “existing duplicate records in EntitySubscription” error. Something like this
After step 2
1. Add one Fast Lookup element to get the list of User’s Id, those are already followed by LoggedIn User
2. Add one Loop element to extract the Id’s from the SObject Collection Variable
3. Use Decision element to compare the values {!Sov_SubscriberList.ParentId} != {!User.Id}, then go ahead else skip the Assignment process