Posted at 9:01 AM by Rakesh Gupta, on January 26, 2021
Big Idea or Enduring Question:
How can we develop declarative functionality to add or remove followers from a record?
In Salesforce, a user can followChatter groups or Records. Salesforce provides out-of-the-box functionality so that Chatter group managers can also add/remove people from the group. To manage a record’s followers/subscribers, Salesforce does not have any pre-built functionality to add or remove a follower/subscriber from object records.
Objectives:
After reading this article, you will be able to:
Use Flow to manually add or remove users as subscribers from a record
Understand the component visibility option to create a highly dynamic screen
Learn how to use a Decision element to find whether a Record variable or aRecord collection variable, contains a record
And, last but not the least, discover how to add a Flow to Lightning Record Page and display it to a set of users
Business Use Case
Elise Shelley, a Lead System Administrator at Universal Containers (UC) receives a requirement from his management, they want to develop an application for the user with the role of Direct SalesDirector so that they can use it to add or remove followers/subscribers to Account records.
Automation Champion Approach (I-do):
First of all, I want to say thanks to Andrew Johnson for sharing his idea (7 years ago) and flow (Add follower to record), which he shared in the success community. In this blog, we will use Salesforce Flow to solve the above business requirement. My main aim is to show the various ways to use Salesforce Flow in your organization.
While this can be solved using various automation tools like Apex, etc, we will use Screen Flow.
Before proceeding ahead, you have to understand the EntitySubscriptionobject.The object represents a user‘s subscription – whether the user follows a record or other users. A user can subscribe to a record or to another user.
Field Name
Details
SubscriberId
The Id of the User who is following the record or user.
ParentId
The Id of the record or user which the user is following.
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.Let’s begin building this automation process.
Posted at 1:50 PM by Rakesh Gupta, on November 21, 2020
Big Idea or Enduring Question:
How do you run a Lightning Flow in system mode?
Objectives:
This blog post will help us to understand the following
Difference between user mode vs system mode?
How to create a flow that runs in the system mode
Business Use case
Vigne Kozacek is working as a System Administrator at Universal Containers (UC). They normally grant read access to account records to account team members. He received a requirement to develop an application that will allow all users to add Chatter followers to the account record without editing it. (It should also work in case if they have only read access to the account record.)
Automation Champion Approach (I-do):
In this article Getting Started with Process Builder – Part 20 (Add Chatter Followers to Record), we had discussed a way to auto-add Chatter followers to an account record using Process Builder. But it will only work for System Administrators or users with the Edit permission on the Account object. There are few business scenarios where a business wants to implement this for all users so that anyone can add followers without editing the account record. Let’s start working through the solution for the business use case.
We will use Flow and Process Builder because it runs in system mode. Before proceeding ahead, you have to understand User mode and System mode in Salesforce.
System mode:In which the object and field-level permissions of the current user are ignored.
User mode: In which the permissions, field-level security, and sharing rules of the current user are enforced.
A few points to remember
By default, ScreenFlowruns in user mode.
But Salesforce provides an ability to runs it insystem mode.
Record-Trigged Flowalways runs in system mode.
Scheduled-Trigged Flowalways runs in system mode.
Process Builderruns in system mode.
When you launch aFlowusing theProcess Builder, then it will run in system mode.
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.
Let’s begin building this automation process.
Guided Practice (We-do):
There are 5 steps to solve Vigne’s business requirement using Lightning Flow. We must:
Define flow properties for screen flow
Create a text variable
Create a screen to capture the user data
Add a screen element
Add a Lookup component
Add a create records element
Setup the flow runtime mode
Create a quick action
Step 1: Define Flow Properties
Click Setup.
In the Quick Find box, type Flows.
Select Flows then click on the New Flow.
Select the Screen Flowoption and click on Next and configure the flow as follows:
How do you want to start building: Freeform
It will open the flow designer for you.
Step 2: Create a Text Variable
Want the quick action to send the record’s ID to your flow? Create a variable like below and the rest Salesforce will handle for you.
Under Toolbox, select Manager. Click on the New Resource.
Input the following information:
Resource Type: Variable
API Name: recordId
Data Type: Text
Default Value: {!$GlobalConstant.EmptyString}
Check Available for Input
Check Available for Output
Click Done.
Step 3.1: Add a Screen Element
Under Toolbox, select Elements. Drag and drop Screen onto the canvas.
Input the following information:
EnterLabel theAPI Name will auto-populate.
Click Done.
Step 3.2: Add a Lookup Component to capture the user data whom they want to make a follower of the record
Under Input section on ScreenElement. Drag and drop Lookup onto the screen.
Input the following information:
EnterAPI Name.
Field API Name: CreatedById (Enter the field API Name that will show up in the list box to represent a record.)
Label: Select a Follower (Enter a label that appears next to the lookup control)
Object API Name: Account ( Enter the object API name)
Required: {!$GlobalConstant.True}
Click Done.
Step 3.3: Add a Create Records Element to add followers into the Record
Under Toolbox, select Elements. Drag and drop Create Records onto the canvas.
Input the following information:
EnterLabel theAPI Name will auto-populate.
How Many Records to Create: One
How to Set the Record Fields: Use separate resources, and literal values
Object: Entity Subscription
Set Field Values for the Entity Subscription
Row 1:
Field: ParentId
Value: {!recordId}
Click Add Row
Row 2:
Field: SubscriberId
Value: {!Select_a_Follower.recordId} (RecordId from screen component lookup field added in the step 3.2)
Click Done.
Step 4: Setup the Flow Runtime Mode
For a flow running in the user context, the running user’s profile and permission sets determine the object permissions and field-level access of the flow. When a flow attempts to create, read, edit, or delete Salesforce data, it enforces the running user’s permissions and field-level access. For example, if the running user doesn’t have the edit permission for the Account object, and the flow attempts to update account records, an error occurs. If the running user doesn’t have permission to edit the Rating field on the Account object, and the flow attempts to update that field, an error occurs.
You can set a flow version to always run in the system context, overriding the context it normally runs in. If you choose system context with sharing, the flow respects org-wide default settings, role hierarchies, sharing rules, manual sharing, teams, and territories. But it doesn’t respect object permissions, field-level access, or other permissions of the running user.
Connect the elements. It will look like the image below.
Click Save.
Enter Flow Label theAPI Name will auto-populate.
Click Show Advanced.
How to Run the Flow: System Context Without Sharing-Access All Data
Type: Screen Flow
API Version for Running the Flow: 50
Interview Label: Add details to Account object {!$Flow.CurrentDateTime}
Click Save.
Almost there! Once everything looks good, click the Activate button.
Step 5: Create a Quick Action – Add Follower
The next step is to create a quick action (Add Follower) on the Account object to call the Flow and add it to the page layout.
Click Setup.
In the Object Manager, type Account.
Select Buttons, Links, and Action, then click New Action.
Input the following information:
SelectFlow as Action Type.
Select Add Follower to Record as Flow.
EnterLabel the Name will auto-populate.
Click Save.
Make sure to add the above quick action on the page layout.
Proof of Concept
In this demo, I am going to use Adam Smith’s account (Profile assigned – Standard Read-Only).
The next step is to click on the Add Follower button and follow the instructions available on the Flow screen.
Finally, check out the Follower section available on the record detail page.
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world?
Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.