Add a Topic to Multiple Records

Advertisements

Last Updated on February 10, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

  • How can you allow your users to add a topic to multiple records?
  • How do you pass record IDs from a list view to Salesforce Flow? 

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

In the past written a few articles related to Topics and automation. You may want to check them out.  

  1. Getting Started with Process Builder – Part 39 (Auto-assign a topic to a record)
  2. Getting Started with Process Builder – Part 41 (Email notification on TopicAssignment)

I have never found an out-of-the-box solution to Add a Topic to multiple records. In this article, we will create automation for similar functionality without using code.

Objectives:

This blog post will help us to understand the following

  • Launch a Flow from the list view and pass the selected record ids to Flow
  • Use a Screen a flow to take the user input 
  • Use a Decision element to find – record variable contains a record or not
  • Use Flow to Create Records (Bulk safe) 

Business Use Case

Brenda David is working as a System administrator at Universal Containers (UC). She has received a requirement from the management to create an automation that allows users to add a topic to selected records (Opportunities) in the list view. 

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenarioWe will use Salesforce Flow, Custom Button, and ListView to solve the requirement. 

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 3 steps to solve Brenda’s business requirement using Screen Flow. We must:

  1. Salesforce Flow Steps: (Screen Flow)
    1. Create a text variable to store topic Id
    2. Create a text collection variable to store record Ids from the opportunity list view 
    3. Add a screen to capture the user data
      1. Add a Text component
    4. Add a get record element to find the topic id
    5. Add a decision element to check the text variable (from step 1.4)
    6. Add a create records element to create a new topic
    7. Add a loop element to extract Ids from the collection variable (from step 1.2) 
    8. Add an assignment element to Assign the values into the record variable
    9. Add an assignment element to add the record variable to a record collection variable
    10. Add a create records element to insert data from the record collection variable
  2. Create a custom button on opportunity
  3. Add the custom button to the opportunity list view 

Step 1.1: Salesforce Flow – Add a Text Variable to Store Topic Id

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Screen Flow option and click on Next and configure the flow as follows: 
  5. Under Toolbox, select Manager, then click New Resource to store Topic Assignment record.
  6. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varTTopicId
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  7. Click Done.

Step 1.2: Salesforce Flow – Add a Text Collection Variable to Store Record Ids from The Opportunity List View 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Under Toolbox, select Manager, then click New Resource to store Topic Assignment record.
  5. Input the following information: 
    1. Resource Type: Variable
    2. API Name: ids
    3. Data Type: Text
    4. Select Allow multiple values (collection)
    5. Select Available for Input
    6. Select Available for Output
  6. Click Done.

Step 1.3: Salesforce Flow – Add a Screen Element 

  1. Under Toolbox, select Screen Elements. Drag and drop Screen onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
  3. Click Done

Step 1.3.1: Add a Text Component to Capture the Topic Name

  1. Under Input section on Screen Element. Drag and drop the Text component onto the screen. 
  2. Input the following information:
    1. Label: Topic Name
    2. The API Name will auto-populate.
    3. Required: {!$GlobalConstant.True}
  3. Click Done.

Step 1.4: Lightning Flow – Adding a Get Record Element to Find the Topic 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: {!Topic_Name}
  7. How Many Records to Store:
    1. select Only the first record
  8. How to Store Record Data:
    1. Choose the option to Choose fields and assign variables (advanced)
      1. Where to Store Field Values: In separate variables
      2. Select Variables to Store Topic Fields:
      3. Row 1:
        1. Field: Id
        2. Variable: {!varTTopicId}
    2. Select When no records are returned, set specified variables to null.
  9. Click Done.

         

Step 1.5: Salesforce Flow – Using Decision Element to Check the Text Variable (from step 1.4)

Now we will use the Decision element to check the Text Variable from step 1.4 to find if it returns the record or not. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!varTTopicId}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.True}
  6. Click Done.

Step 1.6: Salesforce Flow – Adding a Create Records Element to Create a New Topic

  1. Drag-and-drop the Create Records element onto the Flow designer. 
  2. Enter a name in the Label (Create a Lead) field; the API Name will auto-populate.
  3. For How Many Records to Create – select One.
  4. For How to Set the Record Fields – select Use separate resources, and literal values.
  5. Select the Topic object from the dropdown list.
  6. Set Field Values for the Topic
    1. Row 1:
      1. Field: Name
      2. Value: {!Topic_Name}
  7. Select Manually assign variables
  8. Store Topic ID in Variable: 
    1. Variable: {!varTTopicId}
  9. Click Done.

Step 1.7: Salesforce Flow –  Add a Loop Element to Retrieve Records from Collection Variable 

  1. Drag-and-drop the Loop element onto the Flow designer. 
  2. Enter a name in the Label (Extract Ids) field – the API Name will auto-populate.
  3. For Collection Variable select {!ids}.
  4. For Specify Direction for Iterating Over Collection select the option First item to last item.
  5. Click Done.

Step 1.8: Salesforce Flow – Adding an Assignment Element to Assign the Values into a Record Variable

  1. Create a Record Variable varRTopicAssignment type Topic Assignment to link the record with the topic.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label (Assign Topic to Record) field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRTopicAssignment.TopicId}
      2. Operator: Equals
      3. Value: {!varTTopicId}
    2. Add Assignment 
    3. Row 2:
      1. Field: {!varRTopicAssignment.EntityId}
      2. Operator: Equals
      3. Value: {!Extract_Ids}
  5. Click Done.

Step 1.9: Salesforce Flow –  Adding an Assignment Element to Add the Record Variable to Record Collection Variable

  1. Create a Record Collection Variable varRTopicAssignments type Topic Assignment to store record variable (created in step 1.8) for the bulk process.
  2. Drag-and-drop the Assignment element onto the Flow designer. 
  3. Enter a name in the Label (Add Records into a Collection) field – the API Name will auto-populate.
  4. Set Variable Values
    1. Row 1:
      1. Field: {!varRTopicAssignments}
      2. Operator: Add
      3. Value: {!varRTopicAssignment}
  5. Click Done.

Step 1.10: Salesforce Flow – Adding a Create Records Element to Insert Topic with the Records  

  1. Under Toolbox, select Element
  2. Drag-and-drop the Create Records element onto the Flow designer. 
  3. Enter a name in the Label (Create TopicAssignment) field- the API Name will auto-populate.
  4. For How Many Records to Create select Multiple.
  5. Map Record Collection: {!varRTopicAssignments}
  6. Click Done.


In the end, Brenda’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. Type: Screen Flow
  5. API Version for Running the Flow: 51
  6. Interview Label: Add Topic to multiple records {!$Flow.CurrentDateTime}
  7. Click Save

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

Now navigate to the flow details page and copy the Flow URL.

Step 2: Create a Custom List Button – Add Topic 

The next step is to create a custom list button (Add Topic) on the Opportunity object to call the Flow, later we will add the button to the list view. 

  1. Click Setup.
  2. In the Object Manager, type Opportunity.
  3. Select Buttons, Links, and Action, then click New Button or Link.
  4. Input the following information:
    1. Display Type: List Button
    2. Select Display Checkboxes (for Multi-Record Selection)
    3. Select Add Follower to Record as Flow.
    4. Select Field type:  /flow/rakeshistomMVP/Add_Topic_to_multiple_records
  5. Click Save.

Step 2: Add the Custom List Button to Opportunity List View 

The next step is to add the custom list button (Add Topic) to the Opportunity list view. 

  1. Click Setup.
  2. In the Object Manager, type Opportunity.
  3. Select Search Layouts for Salesforce Classic, then click Edit List View.
  4. Custom Buttons
    1. Move Add Topic from Available Buttons Section to Selected Buttons section. 
  5. Click Save.

 

Proof of Concept

Now Onwards, a sales rep can use the Add Topic button on the list view to add topic #Q12021 to multiple Opportunities. 

  1. Navigate to the Opportunities tab and select few opportunities and click on the Add Topic button.
  2. The next step is to enter the Topic Name.
  3. Once everything looks good, click the Next button.   
  4. The final step is to open the topic details page and verify the tagged records.

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.

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

3 thoughts on “Add a Topic to Multiple Records

  1. This worked beautifully! I can’t believe how much work you just saved me. Minor issue I’m having, when the flow launches, it looks like a classic screen flow. Any ideas how to fix it?

    1. Rakesh Gupta – Mumbai – 9x Salesforce MVP | Senior Solution Architect | 8x Author | 5x Dreamforce Speaker | Salesforce Coach | Co-host of AutomationHour.com and AppXchangeHour.Com

      Go to setup | Process Automation Setting and enable lightning run time for flow. Happy to help!

Leave a ReplyCancel reply

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

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%