Big Idea or Enduring Question:
- How can you automatically add topic(s) to a record?
Objectives:
After reading this blog, you’ll be able to:
- Use record-triggered flow to automatically add topics to a record
- Use the get element to find the topic id instead of hard coding of Id
- Use create records element to associate a topic with a record
- and much more
Business Use case
Pamela Kline is working as a System Administrator at Gurukul on Cloud (GoC). She has received a requirement from the management that if a new opportunity is created with an amount greater than $1M then auto adds existing topic #KeyAccount to the opportunity record.
Automation Champion Approach (I-do):
Topics for Objects, allow us to organize the records by using topics the same as Chatter. Topics help to organize records in a better way and make the search easier for you. For example, if you post that you’re working on a presentation for Dreamforce22, you might want to add the hashtag topic #Dreamforce22 or #DF22 in your updates.
Anyone can click on these topics to find out more information about Dreamforce22 and see what people and groups are talking about Dreamforce22. You can also find all records tagged with the topic Dreamforce22.
To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. One reason for using Flow is EntityId is not accessible in the email template, which means you can not get the record Id where the topic is get associated.
Let’s take a pause here, and familiarize ourselves with the TopicAssignment and Topic Objects in Salesforce.
Object Name | Details |
TopicAssignment | It represents the assignment of a topic to a particular feed item or record. |
Topic | It Represents a topic on a Chatter post or record. |
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it.
Let’s begin building this automation process.
Guided Practice (We-do):
There are 6 steps to solve Pamela’s business requirement using Record-Triggered Flow. We must:
- Define flow properties for record-triggered flow
- Create a formula to determine whether the opportunity is created or updated
- Add a decision element to check if the opportunity amount is greater than $1M
- Add a get records element to find the topic (KeyAccount) details
- Add a decision element to check if topic keyAccount was found or not
- Add a create records element to add a topic to the opportunity record
Step 1: Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flow option, click on Create and configure the flow as follows:
- Object: Opportunity
- Trigger the Flow When: A record is created or updated
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For Action and Related Records
- Click Done.
Step 2: Formula to Determine Whether the Opportunity is Created or Updated
- Under Toolbox, select Manager, then click New Resource to determine whether the record is created or updated.
- Input the following information:
- Resource Type: Formula
- API Name: forB_IsNew
- Data Type: Boolean
- Formula: IsNew()
- Click Done.
Step 3: Using Decision Element to Check if the Opportunity Amount is greater than $1M
Now we will use the Decision element to check if the opportunity amount is greater than $1000000.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.Amount}
- Operator: Greater Than
- Value: 1000000
- Click Add Condition
- Row 2:
- Resource: {!forB_IsNew}
- Operator: Equals
- Value: {!$GlobalConstant.True}
- Row 1:
- When to Execute Outcome: If the condition requirements are met.
- Click Done.
Step 4: Adding a Get Record Element to Find Topic (KeyAccount) Details
The next step is to use the Get Records element to find chatter topic keyAccount details.
- On Flow Designer, below the > $1M node, click on the +icon and select the Get Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Topic object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: Name
- Operator: Equals
- Value: KeyAccount
- Row 1:
- 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: Using Decision Element to Check If Chatter Topic was Found or Not
Now we will use the Decision element to check the Record Variable from step 4 to find if it returns the Chatter topic or not.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!Get_Topic}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Row 1:
- When to Execute Outcome: If the condition requirements are met.
- Click Done.
Step 6: Add Action – Create a Record
The next step is to associate topic keyAccount to the newly created opportunity, for this, we will use the Create Records element.
- On Flow Designer, below the Yes node, click on the +icon and select the Create Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Input the following information:
- Enter Label the API Name will auto-populate.
- How Many Records to Create: One
- How to Set the Record Fields: Use separate resources, and literal values
- Object: Topic Assignment
- Set Field Values for the Topic Assignment
- Row 1:
- Field: EntityId
- Value: {!$Record.Id}
- Click Add Field
- Row 2:
- Field: TopicId
- Value: {!Get_Topic.Id}
- Click Done.
In the end, Pamela’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 54
- Interview Label: Auto Assign Topic to Opportunity {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
If a sales rep creates or updates the opportunity with an amount of more than $1.2M, the Record-triggered flow will fire and automatically add #KeyAccount to it.
- Navigate to the Opportunities tab and create a new Opportunity record with an amount of 1.2 M, as shown in the following screenshot:
- Check out the Topic section of the 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? Feel free to share in the comments below.