Auto Delete System Generated Chatter Posts

Auto Delete System Generated Chatter Posts

Last Updated on April 3, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

How do you delete system-generated Chatter posts?

Objectives:

After reading this blog post, the reader will be able to:

  • Map lead custom field to account custom field 
  • Create a record-triggered flow to delete records
  • and much more

Business Use case

Warren Mason is working as a System Administrator at Universal Containers (UC). When we convert the Lead, an automatic chatter post appears on the Account feed i.e., UserName converted a lead to this account, as shown in the following screenshot:

Warren has a requirement to auto-delete such system-generated posts upon lead conversion.

Automation Champion Approach (I-do):

Salesforce Chatter is a great way to boost collaboration in your organization. A user can post statuses, links, and files and comment on others’ posts. However, many times I have found that people are looking for ways to delete system-generated Chatter posts.

To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. Let’s breakdown the solution into the following steps for understanding:

Before proceeding, you have to understand the Feed table in Salesforce. All objects have a default related Feed object. 

  • For custom objects, all feeds are named as CustomObject__Feed, where CustomObject__c is the name of the related custom object, such as JobApplication_Feed.
  • For standard objects, all feeds are named as ObjectFeed, where Object is the name of the related standard object, such as LeadFeed

Now you have to understand the below-mentioned object in Salesforce:

  • AccountFeed: – This object represents a single feed item in the feed displayed on the detail page for a Lead record.

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 understand it.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 4 steps to solve Warren’s business requirement using Record-Triggered Flow. We must: 

  1. Create a custom checkbox field on Lead
  2. Create a custom checkbox field on the Account
  3. Map custom lead fields for lead conversion 
  4. Salesforce Flow Steps:
    1. Define flow properties for record-triggered flow
    2. Add a scheduled path
    3. Add a delete records element to delete system generated post 

Step 1: Creating a Checkbox Field on Lead Object

  1. Click Setup.
  2. In the Object Manager, type Lead.
  3. Select Fields & Relationships, then click New.
  4. Select Checkbox as Data Type, then click Next.
  5. Enter Field Label and click the tab key, the API Name will populate. 
  6. As a best practice, always input a description
  7. Default Values: Checked
  8. Set the Field-level Security for the profiles, make sure to set this field as read-only. 
  9. Do not add this field on the Page Layout.
  10. Click Save.

Step 2: Creating a Checkbox Field on Account Object

  1. Click Setup.
  2. In the Object Manager, type Account.
  3. Select Fields & Relationships, then click New.
  4. Select Checkbox as Data Type, then click Next.
  5. Enter Field Label and click the tab key, the API Name will populate. 
  6. As a best practice, always input a description
  7. Default Values: Unchecked
  8. Set the Field-level Security for the profiles, make sure to set this field as read-only. 
  9. Do not add this field on the Page Layout.
  10. Click Save.

Step 3: Map Custom Lead Fields for Lead Conversion 

  1. Click Setup.
  2. In the Object Manager, type Lead.
  3. Select Fields & Relationships, then click Map Lead Fields.
    1. You can map each of your organization’s Lead custom fields to one of your custom Account, Contact, or Opportunity fields.
  4. Map the Lead Conversion field as shown in the screenshot below.
  5. Click Save.

Step 4.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 Record-Triggered Flow option, click on Create and configure the flow as follows:
    1. Object: Account
    2. Trigger the Flow When: A record is created
    3. Set Entry Criteria
      1. Condition Requirements: All Conditions Are Met (AND)
        1. Row 1:
          1. Field: Lead_Conversion__c
          2. Operator: Equals
          3. Value: {!$GlobalConstant.True}
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 4.2: Salesforce Flow – Add Scheduled Paths

The purpose of using a scheduled path is to allow Salesforce to generate the scheduled posts. As system-generated posts are inserted to AccountFeed object i.e. child of Account. 

  1. Under Start, select Add Scheduled Paths (Optional).
  2. Under SCHEDULED PATHS, click on the  New Scheduled Path.
  3. Under Scheduled Path Details, enter the Label the API Name will auto-populate.
  4. Time Source: Lead: Created Date
  5. Offset Number: 0
  6. Offset Options: Hours After
  7. Advanced Options
    1. Batch Size: 100
  8. Click Done.

Step 4.3: Salesforce Flow – Add a Delete Records Element to Delete System Generated Posts

  1. On Flow Designer, under Wait 0 hr Node click on the +icon and select the Delete Records element.
  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 Account Feed object from the dropdown list.
  5. Set Filter Conditions
    1. Row 1:
      1. Field: ParentId
      2. Operator: Equals
      3. Value: {!$Record.Id}
  6. Click Done.


In the end, Warren’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: 54
  5. Interview Label: Delete system generated posts {!$Flow.CurrentDateTime}
  6. Click Save

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

Proof of Concept

Now onwards, if a business user converts a lead, Salesforce Flow will automatically trigger and launch the Flow. It will then delete the system-generated post after a few minutes. Let’s test it out.

  1. Below is the current status of lead Ms. Kristen Akin before conversion.
  2. After you convert the Lead, you will be directed to the Account Detail page. Click on the Account Chatter feed.
  3. Final Output
    1. Wait a few minutes and refresh the Account detail page. 
    2. Check out the Account feed. The Chatter post will be deleted.

 

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.

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)

17 thoughts on “Auto Delete System Generated Chatter Posts

  1. Thanks for this. I implemented it and it works as described, however as an earlier comment notes, there is potentially some collateral damage. When I was testing, it would typically take around one minute for the AccountFeed record to be deleted. If, in that window, I added other Chatter Posts to the Account, they would also be deleted (undesirable behavior). My fix to this: change the Flow so that it first does a RecordLookup – where you lookup the AccountFeed record, sorting by CreatedDate – it will only grab the first AccountFeed record, which should be the offending post. Then you can delete it.
    Thanks again for posting this.
    chris

  2. I found that this deletes everything – event older, unrelated chatter posts. I switched the object to FeedItem and just deleted the most recent one attached to the account, and that kept the history.

  3. Thanks for this info. Would you have any suggestions on how to modify this for another process? I need to auto delete all system generated feeds on cases. I am getting a flow error that says Error Occurred: No records in Salesforce match your delete criteria.

    1. You are getting this error because Flow is unable to find any system generated Feed.
      To avoid such errors, use Decision element to make sure that there is a Chatter feed.

        1. 1. First, put a Record lookup element (Criteria is same as Record Delete element) to query Chatter feed
          2. Then use Decision element to verify the outcome of Record Lookup element to make sure that there is something to delete.
          3. In case, if there are Chatter feed then use Record Delete element to delete Chatter Feeds

  4. I am unable to see accountfeed object. How I can see that in flow record delete object inbox?
    send me reply on my email address —

    1. First, enable Feed Tracking for Account object by navigating From Setup, enter Feed Tracking in the Quick Find box, then select Feed Tracking.

  5. Hi Rakesh,

    Can you assist me with this process? I’ve attempted to recreate this and it’s not working for me in any of my environments — so I’m wondering what I’m doing wrong.

    Thanks in advance!

  6. Hi, Rakesh can you please guide me how to auto generate a message from Chatter (Happy birthday or anniversary) to individuals of a group and have the chatter message auto generate a post to the group?

    1. Yes, it is possible to post birthday messages to a Chatter group. Before that, you have to save Date of Birth in a field. Then use a formula field to calculate birthday in the current year, and then use Process builder with time-based actions.

Leave a Reply

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