Last Updated on June 22, 2022 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 Delete Chatter Messages Using Salesforce Flow, 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:
- Use automation to increase user permissions
- Create a custom object to store the Id of a Chatter conversation
- Use Record-Triggered 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 isn‘t 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
- A private message can include up to 9 members, including yourself.
- Messages sent will not be viewable through Chatter feed, Chatter Profile, or Global Search results.
- You can’t delete messages or conversations.
- An administrator with the Manage Chatter Messages permission can view and delete all users‘ messages in Chatter. This may be necessary for compliance purposes
- Messages are hard deleted. They aren’t sent to the Recycle Bin.
- Deleted messages aren’t included in message search results.
- If all messages in a conversation are deleted, the conversation doesn‘t show in My Messages and can’t be retrieved via the Chatter REST API.
- 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 Salesforce Flow and Custom Object 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 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 understanding it.
Let’s begin building this automation process.
Guided Practice (We-do):
There are 3 steps to solve Rachel’s business requirement using Record-triggered Flow. We must:
- Grant manage chatter permissionÂ
- Create a custom object with few fields that will be used to save the Id of the Chatter conversation, which the users want to delete
- Salesforce Flow Steps:
- Define flow properties for record-triggered flow
- Add a decision element to check Chatter Conversation Id field is not null
- Add a Delete Records element to delete the Chatter Conversation
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.
- Click Setup.
- In the Object Manager, click Create | Custom Object.
- Now create a custom object Delete Chatter Conversation and fields as shown in the screenshot below:Â
- 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: Define Flow Properties
The next step is to create a Flow to implement the business requirement, i.e. delete chatter conversation when someone created a record in the custom object created in step #2.
- 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: Delete Chatter Conversation
- Trigger the Flow When: A record is created
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For Action and Related Records
- Click Done.
Step 3.2: Using Decision Element to Check If Chatter Conversation Id Field is Populated or Not
The next step is to check the chatter conversation-id field is populated or not. To check this, we will use the Decision element.
- 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.Chatter_conversation_Id__c}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Row 1:
- Click Done.
Step 3.3: Add Action – Delete Record
The next step is to delete the chatter conversation. For this, we will use the Delete Records element.
- On Flow Designer, below the Yes node, click on the +icon and select the Delete Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- For How to Find Records to Delete select Specify conditions.
- Select the ChatterMessage object from the dropdown list.
- Set Filter Conditions
- Row 1:
- Field: ConversationId
- Operator: Equals
- Value: {!$Record.Chatter_Conversation_Id__c}
- Row 1:
- Click Done.
In the end, Rachel’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: 55
- Interview Label: Delete Chatter Conversation {!$Flow.CurrentDateTime}
- Click Save.Â
Almost there! Once everything looks good, click the Activate button. Â
Proof of Concept
- Logged in as Platform User Brenda David (Custom Platform profile).
- No extra permission is assigned to this user apart from Create and Read permission on the Delete Chatter Conversation object.
- 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 Id
- 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:
- A window will open at the bottom of the current screen. Find and copy the Chatter Conversation Id as shown in the following screenshot:
- Create a new record in the Delete Chatter Conversation object, as shown in the following screenshot
- Navigate to the Chatter messages and check it out now. The conversation (i.e. test2w333?) sent by System Administrator Rakesh Gupta gets deleted.
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? Feel free to share in the comments below.