Merge Chatter Topics with the Help of Salesforce Flow

Merge Chatter Topics with the Help of Salesforce Flow

Last Updated on February 10, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How can users be allowed to Merge Chatter Topics?

Topics for Objects allow us to organize the records using Chatter’s topic. 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.

Salesforce allowed you to delete the topic from the user interface – but not merge two different Chatter Topics. This article goes a step ahead and explains how to merge two chatter topics without using a single line of code. 

I have written a few articles on automating Topic association and email notification in the past. Why not check them out while you are at it?! 

  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)

Objectives:

After reading this article, you will be able to:

  • Use Flow to merge two topics with preserving the associated links of records, posts, and files 
  • Learn how to work with the picklist component (Screen Flow)
  • Learn how to use a Decision element to find whether a Record variable or a Record collection variable contains a record
  • Find out how to use the Loop element to extract records from a record collection variable.
  • And, last but not least, discover how to use the Create Records element to create multiple records at once (Bulk Safe)

Business Use case

Rachel Gillett is working as a System administrator at Universal Containers (UC). Users at UC are using the Chatter hashtag to organize their posts, records, and files. She has received management requirements to allow their users to merge two topics from the Salesforce user interface (for example, #DF21 and Dreamforce21).

Automation Champion Approach (I-do):

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 TopicAssignment object. It represents the assignment of a topic to a specific feed item, record, or file.

Field Name Details
EntityId Identifier of the feed item or record.
TopicId Identifier of the topic.

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 Rachel’s business requirement using Screen Flow. We must:

  1. Salesforce Flow Steps: Define flow properties 
    1. Add a screen to capture the user’s input.
      1. Add a picklist component to display the Topics (for Source Topic)
      2. Add a picklist component to display the Topics (for Target Topic)
    2. Add a Get Records element to find the associated records, posts, and files for the source topic 
    3. Add a Decision element to check if the record collection variable (from step 1.2) is null or not
    4. Add a loop element to extract records from the record collection variable (from step 1.2) 
    5. Add an Assignment element to Assign the target topicId to the loop variable 
    6. Add an Assignment element to add the Record variable to a Record collection variable.
    7. Add a Delete Records element to delete the source topic
    8. Add a Create Records element to associate records, posts, and files from source topic to the target topic 
  2. Add flow to the lightning home page

Step 1: Salesforce 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 Screen Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
  5. It will open the flow designer for you.

Step 1.1: Salesforce Flow – Add a Screen Element  

  1. Under Toolbox, select 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.1.1: Salesforce Flow – Add a Picklist Component to Display the Topics (for Source Topic) 

  1. Under Input section on Screen Element. Drag and drop the Picklist component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Data Type: Text
    3. Under Select Choices 
      1. Click + New Resource; it will open a pop-up for you
      2. Resource Type: Record Choice Set
      3. API Name: TopicList
      4. Object: Topic
      5. Filter Topic Records
        1. Row 1:
          1. Field: Id
          2. Operator: Does Not Equal 
          3. Value: {!$GlobalConstant.EmptyString}
      6. Configure Each Choice
        1. Choice Label: Name
        2. Data Type: Text
        3. Choice Value: Id
  3. Click Done
  4. Click Done.

Step 1.1.2: Salesforce Flow – Add a Picklist Component to Display the Topics (for Target Topic) 

  1. Under Input section on Screen Element. Drag and drop the Picklist component onto the screen. 
  2. Input the following information:
    1. Enter a name in the Label field; the API Name will auto-populate.
    2. Data Type: Text
    3. Under Select Choices 
      1. Choice: {!TopicList}
  3. Click Done

Step 1.2: Salesforce Flow – Adding a Get Record Element to Find the Associated Records, Posts, and Files for Source Topic 

The next step is to use the TopicAssignment object to find the associated records, posts, and filed linked to the source topic. 

  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 TopicAssignment object from the dropdown list.
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Id: TopicId
      2. Operator: Equals
      3. Value: {!Source_Topic}
  7. How Many Records to Store:
    1. select All records
  8. How to Store Record Data:
    1. Choose the option to store all fields Automatically. 
  9. Click Done.

Step 1.3: Salesforce Flow – Using Decision Element to Check the Record Collection Variable (from step 1.2)

Now we will use the Decision element to check the Record Collection Variable from step 1.2 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: {!Find_TopicAssignment}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
  6. Click Done.

Step 1.4: Salesforce Flow –  Add a Loop Element to Retrieve Records from Record Collection Variable (from step 1.2) 

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

Step 1.5: Salesforce Flow – Adding an Assignment Element to Assign the Target TopicId (to link Records, Posts and Files from Source Topic to Target Topic)

  1. Drag-and-drop the Assignment element onto the Flow designer. 
  2. Enter a name in the Label field – the API Name will auto-populate.
  3. Set Variable Values
    1. Row 1:
      1. Field: {!Loop_Through_TopicAssignment.TopicId}
      2. Operator: Equals
      3. Value: {!DestinationTopic}
  4. Click Done.

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

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

Step 1.7: Lightning Flow – Add a Delete Records Element to Delete the Source Topic

The next step is to delete the source topic. To do this, drag-and-drop Delete Records element.

  1. Drag-and-drop Delete Records element onto the Flow designer. 
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For How to Find Records to Delete select Specify conditions.
  4. Select the Topic object from the dropdown list.
  5. Set Filter Conditions
    1. Row 1:
      1. Field: Id
      2. Operator: Equals
      3. Value: {!Source_Topic}
  6. Click Done.

Step 1.8: Salesforce Flow – Adding a Create Records Element to associate Records, Posts, and Files from Source Topic to Target Topic 

  1. Under Toolbox, select Element
  2. Drag-and-drop the Create Records element onto the Flow designer. 
  3. Enter a name in the Label 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, Rachel’s Flow will look like the following screenshot (I turned on Auto-Layout) for this flow:

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. How to Run the Flow: System Context Without Sharing—Access All Data
  5. Type: Screen Flow
  6. API Version for Running the Flow: 51
  7. Interview Label: Merge Chatter Topcis {!$Flow.CurrentDateTime}
  8. Click Save.

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

Step 2: Add a Flow to Lightning Home Page

The next step is to distribute a flow to Lightning Experience or Salesforce app users by embedding it on a Lightning home page.

  1. Click Setup.
  2. In the Quick Find box, type Lightning App Builder.
  3. Select Lightning App Builder then click on the Edit next to the Home page.
  4. From the Lightning Components pane on the left, drag the Flow component onto the Lightning page canvas.
  5. Input the following information:
    1. Select Merge Chatter Topics flow
  6. Click Done.

Once everything looks good, click the Save button. 

Proof of Concept

Now onwards, Sales users can use this tool and merge chatter topics. 

  1. Currently, there are two records are associated with the topic Quarter 2021 as shown in the following screenshot:
  2. Currently, there are one record is associated with topic Q12021 as shown in the following screenshot:
  3. Now use the flow to merge topic Quarter 2021 with Q12021 as shown in the following demo:

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 “Merge Chatter Topics with the Help of Salesforce Flow

Leave a 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