Getting Started with Process Builder – Part 36 (Delete Complete Chatter Conversation)

Getting Started with Process Builder – Part 36 (Delete Complete Chatter Conversation)

Last Updated on November 30, 2020 by Rakesh Gupta

Big Idea or Enduring Question:

How can users be allowed to delete Chatter conversation?

This is a continuation of my previous article Getting Started with Process Builder – Part 35 (Delete Chatter Messages), In that I had discussed a way which allows your users to delete Chatter messages. This article goes a step ahead and explains, how to delete all messages at once, i.e. how to delete a Chatter conversation. Chatter conversation is nothing but messages that members have sent or received. 

Objectives:

After reading this article, the reader will be able to:

  • Launch a flow from Process Builder
  • Use automation to increase user permissions
  • Create a custom object to store the Id of a Chatter conversation
  • Use Flow to delete the Chatter Conversation 

Business Use case

Rachel Gillett is working as a System administrator at Universal Containers (UC). She has received a requirement from management to allow their Sales reps (License Type: – Salesforce Platform) to delete Chatter conversation from Salesforce UI.

Automation Champion Approach (I-do):

**Chatter Messages functionality is only available in Classic

First, it is important to understand Chatter messages and Chatter Conversations in Salesforce. Chatter messages let you have secure private conversations with other Chatter users. Use messages to send your colleague a question privately or to communicate with a few selected people when a discussion isnt relevant to everyone you work with. A Chatter conversation consists of messages that conversation members have sent or received.  

Remember the following points for using Chatter messages

  1. A private message can include up to 9 members, including yourself.
  2. Messages sent will not be viewable through Chatter feed, Chatter Profile, or Global Search results.
  3. You can’t delete messages or conversations.
  4. An administrator with the Manage Chatter Messages permission can view and delete all users messages in ChatterThis may be necessary for compliance purposes
    1. Messages are hard deleted. They aren’t sent to the Recycle Bin.
    2. Deleted messages aren’t included in message search results.
    3. If all messages in a conversation are deleted, the conversation doesnt show in My Messages and cant be retrieved via the Chatter REST API.
  5. If after reading the messages in a conversation you want to mark the conversation unread, you can do so only via the Chatter REST API, not via the user interface.

There are a few possible solutions for the above business scenario, but I’ll use Process Builder and Flow to solve the business requirement. As discussed earlier, a System Administrator with the Manage Chatter Messages permission can view and delete all users’ messages in Chatter. Business users are not allowed to delete messages or conversations.

In Salesforce the ChatterMessage object represents a message sent as part of a private conversation in Chatter. There are some relevant fields to identify:

Field Name Details
Id Chatter Message Id
ConversationId The ID of the conversation that the ChatterMessage is associated with.

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 4 steps to solve Rachel’s business requirement using Flow and Process Builder. We must:

  1. Grant manage chatter permission 
  2. Create a custom object that will be used to save the Id of the Chatter message, which the users want to delete
  3. Lightning Flow Steps:
    1. Define flow properties for auto-launched flow
    2. Add a Text variable to store chatter conversation Id
    3. Add a Delete Records element to delete the Chatter conversation 
  4. Process Builder Steps:
    1. Define process properties
    2. Define evaluation criteria
    3. Define process criteria
    4. Add action – flows 

Step 1: Grant Manage Chatter Messages Permission to Users

First, create a Permission Set to grant your user record Manage Chatter Messages permission. Otherwise, you will get an error while building the Flow. The permission can be removed later.

Step 2: Create a Custom Object – Delete Chatter Conversation 

Create a custom object (Delete Chatter Conversation) and a text field to save the Chatter Conversation Id.

  1. Click Setup.
  2. In the Object Manager, click Create | Custom Object.
  3. Now create a custom object Delete Chatter Conversation and fields as shown in the screenshot below: 
  4. Click Save.

Make sure that you have marked the field Chatter_Conversation_Id__c as required and also granted CRUD access to the respective profiles.

Step 3.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 3.2: Lightning Flow – Add a Text Variable to Store Chatter Conversation Id

  1. Under Toolbox, select Manager, then click New Resource to store chatter conversation Id.
  2. Input the following information: 
    1. Resource Type: Variable
    2. API Name: varTChatterConversationId
    3. Data Type: Text
    4. Default Value: {!$GlobalConstant.EmptyString}
    5. Check Available for Input
    6. Check Available for Output
  3. Click Done.

Step 3.3: Lightning Flow – Add a Delete Records Element to Delete Chatter Conversation 

The next step is to delete the chatter conversation. 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 Chatter Message object from the dropdown list.
  5. Set Filter Conditions
    1. Row 1:
      1. Field: ConversationId
      2. Operator: Equals
      3. Value: {!varTChatterConversationId}
  6. Click Done.

In the end, Rachel’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: Delete Chatter Conversation {!$Flow.CurrentDateTime}
  6. Click Save

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

Our next task is to create a Process on the Delete Chatter Conversation object that will call a Flow. To create a Process on the Delete Chatter Conversation object follow the instructions below.

Step 4.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 4.2: Define Evaluation Criteria

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

Step 4.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: Delete Chatter Conversation | Chatter_Conversation_Id__c
      2. Operator:  Is null
      3. Type: Boolean
      4. Value: False
  5. Select All of the conditions are met (AND)
  6. Click Save.

Step 4.4: Add Action – Flows

  1. Below Immediate Actions, click Add Action.
  2. For Action Type, select Flows
  3. Name the action.
  4. Select Flow – Delete Chatter Conversation.
    1. Set Flow variables: 
      1. Row 1
        1. Field: varTChatterConversationId
        2. Type: Field Reference
        3. Value: Delete Chatter Message | Chatter_Conversation_Id__c
  5. Click Save.

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

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

Proof of Concept

  1. Logged in as Platform User Brenda David (Custom Platform profile).Salesforce Platform User
    1. No extra permission is assigned to this user apart from Create and Read permission on the Delete Chatter Conversation object.
  2. Brenda wants to delete a Chatter conversations (all messages in a thread) sent by Sales User Rakesh Gupta, but as a business user when she can’t run a query to get the IdChatter Conversation
  3. To get a Chatter Conversation Id, open the chatter message and right-click on it, and then select Inspect Element, as shown in the following screenshot:Select Inspect Element for a Chatter Conversation
  4. A window will open at the bottom of the current screen. Find and copy the Chatter Conversation Id as shown in the following screenshot:Chatter Conversation Id
  5. Create a new record in the Delete Chatter Conversation object, as shown in the following screenshotCreate a new record
  6. Navigate to the Chatter messages and check it out now. The conversation (i.e. test2w333?) sent by System Administrator Rakesh Gupta gets deleted.

Final Output

Note: – You are only able to delete those Chatter conversations in which you are included, otherwise you will get an error. (There is nothing in Salesforce matching your delete criteria). It’s not applicable to the system administrator with the Manage Chatter Messages permission.

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!

Leave a Reply

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