Posted at 9:00 AM by Rakesh Gupta, on January 7, 2021
Big Idea or Enduring Question:
A warm welcome goes a long way in solidifying a company’s culture! If so then, why not provide existing users an ability to auto-follow new users in chatter?
Chatter is a great way to boost collaboration in your organization. You can Post Status, Links, Files, and Comments on others’ posts, etc. Thebenefitsof following the new users inChatterare the following:
Keep up with what new users are doing; your guidance will expedite, and streamline their on-boarding journey!
Following new users will enable you to track their chatter activities; use this ‘crystal ball’ to help them to improve their productivity!
In the past, I have written a few articles related toUser, Chatter,andautomation. Why not check them out while you are at it?!
On the Trailblazer community, several people have been wondering how to allow their users to auto-follow new users. Salesforce doesn’t have any out-of-the-box feature for this; so,I decided to take a crack at it. This article showshow to develop an app that allows your users to auto-follow news users without code.
Objectives:
After reading this blog post, the reader will be able to:
What is a MIXED DML error and how to avoid it?
Add a Time-dependent action in After-save Record-Triggered Flow
Get the list of user who has opted to follow new users in Chatter
Use a Loop element to work with multiple records
Use After-save Record-Triggered Flow to create a record (Bulk Safe)
Monitor Time-based flow queue
Business Use Case
Warren Mason, Gurukul on Cloud‘s (GoC) awesome System Administrator, received the following requirement – allow usersto auto-follow new users in Chatter. And, make this an optional feature.
Automation Champion Approach (I-do):
While this can be solved using various automation tools like Apex, etc, but we’ll use After-save Record-Triggered Flowto solve it.Check out this articleto understand why we are using after-save record-triggered flow for this scenario.
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.
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.
Guided Practice (We-do):
There are 2 steps to solve Warren’s business requirement using After-save Record-Triggered Flow. We must:Read the rest of this entry!
Posted at 1:12 AM by Rakesh Gupta, on January 2, 2021
Big Idea or Enduring Question:
How do you set up dynamic approval routing?
In Salesforce, auser can use an Approval process to get approval from managers or higher authority.Approval processes route a record to one or more approvers, specifying the steps necessary for a record to be approved, and who must approve it at each step.
In a normal approval process, i.e.,Static approval process, the approvers at each step are explicitly specified in each step approval process, or you can have the submitter choose the approver manually, as shown in the following screenshot:Whereas dynamic approval routing allows us to specify the approvers for each record using Userlookup fields on the record requiring approval. These fields can be populated using Process Builder or Apex, using data from a special custom object/setting that contains all the information needed to route the record. Dynamic approval routing provides the flexibility to route the approval request to different people based on Account Type or some other criteria related to the record. Let’s start with a business use case.
Objectives:
After reading this blog post, the reader will be able to:
Use Before-save Record-Triggered Flow to route approval requests to designated approvers
Use a Decision element to find – record variable or record collection variable contains a record or not
Use an Assignment element to assign default approver to opportunity
Business Use case
Steven Greene is working as a System administrator in Universal Container. He has received a requirement from the management to route opportunity approval requests to designated approvers based on the opportunity’s Lead Source and the opportunity’s account Type.
Automation Champion Approach (I-do):
While this can be solved using various automation tools like Apex or Flow, we will useBefore-save Record-Triggered Flow. This is not something that can be accomplished with Workflow Rules or Process Builder.
Before discussing it, 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 Steven’s business requirement using Salesforce Flow. We must:
Create a custom lookup (with User object) field on the object being approved
Create a custom object that will be used as an approval matrix
Populate the approval matrix, i.e., create a few records in a custom object
Create an approval process
Salesforce Flow Steps:
Define flow properties for record-triggered flow
Add a get records element to find opportunity owner
Add a decision element to check the record collection variable (from step 5.2)
Add an assignment element – assign dynamic approver
Add an assignment element – assign default approver
Step 1: Creating a Custom lookup (user)
On the Opportunity object, create a lookup fieldcalled Opportunity Approver as mentioned in the steps below.
Click Setup.
In the Object Manager, type Opportunity.
Select Fields & Relationships, then click New.
Select Lookup Relationship as Data Type, then click Next.
Select the User object for the Related Tooption, then click Next.
Enter Field Label and click the Next button. The API Name will populate.
As a best practice, always input a description.
Set the Field-level Security for the profiles, make sure to set this field as read-only.
Add this field to Page Layout.
Click Save.
Step 2: Create a Custom Object
The next step is to create a custom object Approver Matrix and a few custom fields to store related information which will use in approval routing.
Click Setup.
In the Object Manager, click Create | Custom Object.
Now create a custom object Approver Matrix and fields as shown in the screenshot below:
The next step is to create approval matrix records that associate the Lead Source and Type to the appropriate Opportunity Approver. For example, if Lead Source = Web and Type = Existing Customer – Upgrade, then one might route the records to Adam Smith as Opportunity Approver. It will look like the following screenshot:
Step 4: Create an Approval Process
Click Setup.
In the Quick Find box, type Approval Processes.
Clicks on theCreate New Approval Process | Use Standard Setup Wizard button.
Select the Opportunity object for Manage Approval Processes For drop-down.
Now create an approval process, as shown in the following screenshot:
Make sure to modify the approver step (Step 3), and select related user Opportunity approver, as shown in the preceding screenshot.
Select the Record-Triggered Flowoption and click on Next and configure the flow as follows:
How do you want to start building: Freeform
Trigger the Flow When: A record is created or Updated
Run Flow: Before the record is saved
Object: Opportunity
Select Any Condition Is Met (OR).
Set Conditions
Row 1
Field: Opportunity | Type
Operator: Does Not Equal
Value: {!$GlobalConstant.EmptyString}
Click Add Condition
Row 2
Field: Opportunity | Lead Source
Operator: Does Not Equal
Value: {!$GlobalConstant.EmptyString}
Choose the Option to Every time a record is updated and meets the condition requirements.
Click Done.
Step 5.2: Salesforce Flow – Adding a Get Record Element
The next step is to get the Opportunity Approver. We will use the Get Records element. To do this drag-and-drop Get Records element onto the canvas and map the fields according to the details below:
Under Toolbox, select Element.
Drag-and-drop Get Records element onto the Flow designer.
Enter a name in the Label field; the API Name will auto-populate.
Select the Approver Matrixobject from the dropdown list.
Select All Conditions Are Met (AND).
Set Filter Conditions
Row 1:
Field: Type
Operator: Equals
Value: {!$Record.Type}
Row 2:
Field: Lead Source
Operator: Equals
Value: {!$Record.LeadSource}
How Many Records to Store:
select Only the first record
How to Store Record Data:
Choose the option to Automatically store all fields.
Click Done.
Step 5.3: Salesforce Flow – Using Decision Element to Check Record Variable Size
Now we will use the Decision element to check the Record Variable from step 5.2 size. If the Text Variable is not equal to null,then we will go ahead and update Approver on the opportunity record. Otherwise, we will update it with a default approver.
Under Toolbox, select Element.
Drag-and-drop Decision element onto the Flow designer.
Enter a name in the Label field; the API Name will auto-populate.
Under Outcome Details,enter theLabel theAPI Name will auto-populate.
Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
Row 1:
Resource: {!Opportunity_Approver}
Operator: Is Null
Value: {!$GlobalConstant.False}
When to Execute Outcome: If the condition requirements are met
Click Done.
Step 5.4: Salesforce Flow – Using Assignment Element to Update Opportunity Approver
The next step is to update an Opportunity record. We will use the Assignmentelement, as we are using before-save flow.
Under Toolbox, select Element.
Drag-and-drop Assignment element onto the Flow designer.
Enter a name in the Label field; theAPI Name will auto-populate.
Set Variable Values
Row 1:
Field: {!$Record.Opportunity_Approver__c}
Operator: Equals
Value: {!Opportunity_Approver.Opportunity_Approver__c} (Record variable from step 5.2)
Click Done.
Step 5.5: Salesforce Flow – Using Assignment Element to Update Default Approver
In case there aren’t any approvers that exist in the Approver Matrix for the current opportunity, then we will update Opportunity Approver to Logged-In user’s manager. We will use the Assignmentelement, as we are using before-save flow.
Under Toolbox, select Element.
Drag-and-drop Assignment element onto the Flow designer.
Enter a name in the Label field; theAPI Name will auto-populate.
Set Variable Values
Row 1:
Field: {!$Record.Opportunity_Approver__c}
Operator: Equals
Value: {!$User.ManagerId}
Click Done.
In the end, Steven’s Flowwill look like the following screenshot:
Once everything looks good, perform the steps below:
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
Now onwards, if a business user updates the Lead Source and Type, Process Builder will automatically populate the Opportunity Approver field.
Currently,Opportunity Approver on opportunity West Mountain Sign is Patrick Trevenen (which is correct based on our matrix which we set up in step 3)as shown in the following screenshot:
Now we update the Type to Existing Customer – Upgradeand Lead Sourceto Web.
Finally, submit an Opportunity record for approval.
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.