Getting Started with Process Builder – Part 39 (Auto Assign a Topic to a Record)

Getting Started with Process Builder – Part 39 (Auto Assign a Topic to a Record)

Last Updated on December 30, 2020 by Rakesh Gupta

Big Idea or Enduring Question:

  • How can you automatically add topic(s) to a record?

Objectives:

This blog post will help us to understand the following

  • Launch a Flow from Process Builder
  • Use Flow and Process Builder to automatically add topics to a record 

Business Use case

Pamela Kline is working as a System administrator at Universal Containers (UC). 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 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 Dreamforce20, you might want to add the hashtag topic #Dreamforce20 or #DF20 in your updates.

Anyone can click on these topics to find out more information about Dreamforce20 and see what people and groups are talking about Dreamforce20. You can also find all records tagged with the topic Dreamforce20.

There are a few possible solutions for the above business scenario. We will use Flow and Process Builder to solve the requirement. Check out this article to understand why we are using after-save record-triggered flow for this scenario. 

Let’s take a pause here, familiar yourself 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 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 Pamela’s business requirement using Flow and Process Builder. We must: 

  1. Lightning Flow Steps:
    1. Define flow properties for auto-launched flow
    2. Add a record variable to store opportunity record data 
    3. Add a get records element to find the id of the topic (KeyAccount)
    4. Add a create records element to add a topic to the opportunity record
  2. Process Builder Steps:
    1. Define process properties
    2. Define evaluation criteria
    3. Define process criteria
    4. Add action – flows 

Step 1.1: Lightning Flow – Define Flow Properties 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. Click Done.

Step 1.2: Lightning Flow – Add a Record Variable to Store Opportunity Record

  1. Under Toolbox, select Manager, then click New Resource to store opportunity record.
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varROpportunity
    3. Data Type: Record
    4. Object Opportunity
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 1.3: Lightning Flow – Adding a Get Record Element to Find the Topic (KeyAccount) Id 

The next step is to use the Get Records element to find the topic #KeyAccount Id.

  1. Under Toolbox, select Element
  2. Drag-and-drop Get Records element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Select the Topic object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: Name
      2. Operator: Equals
      3. Value: KeyAccount
  7. How Many Records to Store:
    1. select Only the first record
  8. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  9. Click Done.

Step 1.4: Lightning Flow – Create Records – Add an Opportunity Team member to Opportunity Follower

The final step is to add the #KeyAccount topic to the opportunity. Drag and drop Record Create onto the flow designer and map the fields according to the below details. Here I am assuming that Topic with the name KeyAccount exists in your org. 

  1. Under Toolbox, select Elements. Drag and drop Create Records onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: Topic Assignment 
    5. Set Field Values for the Topic Assignment 
    6. Row 1:
      1. Field: EntityId
      2. Value: {!varROpportunity.d}
    7. Click Add Field
    8. Row 2:
      1. Field: TopicId
      2. Value: {!Topic_keyAccount_Id.Id}
  3. Click Done.

In the end, Pamela’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 50
  5. Interview Label: Assign topic to a record {!$Flow.CurrentDateTime}
  6. Click Save

Almost there! Once everything looks good, click the Activate button.  

Our next task is to create a Process Builder on the Opportunity object to launch a Flow. To create a Process Builder on the Opportunity object follow the below instructions.

Step 2.1: Define Process Properties

  1. Click Setup.
  2. In the Quick Find box, type Process Builder.
  3. Select Process Builder, then click New.
  4. Name the Process and click the Tab button. The API Name will populate. 
  5. As a best practice, always input a description
  6. The process starts when A record changes.
  7. Click Save.

Step 2.2: Define Evaluation Criteria

  1. Click on the Add Object node to begin selecting the evaluation criteria.
  2. Select the Opportunity object from the dropdown list.
  3. Start the process only when a record is created.
  4. Click Save.

Step 2.3: Define Process Criteria

  1. Click the Add Criteria node to begin defining the process criteria.
  2. Name the criteria.
  3. The criteria should execute actions when the conditions are met.
  4. Set Conditions
    1. Row 1
      1. Field: Opportunity | Amount
      2. Operator:  Greater than
      3. Type: Currency
      4. Value: 1000000
  5. Select All of the conditions are met (AND)
  6. Click Save.

Step 2.4: Add Action – Flows

  1. Below Immediate Actions, click Add Action.
  2. For Action Type, select Flows
  3. Name the action.
  4. Select the flow we just createdAssign topic to a record.
  5. Set Flow Variables: 
    1. Row 1:
      1. Flow Variable: varROpportunity
      2. Type: Field Reference
      3. Value: Select the Opportunity record that started your process
  6. Click Save.



In the end, Pamela’s Process will look like the following screenshot:



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 more than $1.2M, Process Builder will fire and automatically add #KeyTopic to it. 

  1. Navigate to the Opportunities tab and create a new Opportunity record with an amount of 1.2 M, as shown in the following screenshot:
  2. Check out the Topic section of the page

Formative Assessment:

I want to hear from you! 

What did you learn from this post, is it relevant to you, and how will you modify the concepts taught in the post for your own business processes? 

Make a post and tag me on Twitter @automationchamp, using #AutomationChampionPB.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.