Getting Started with Process Builder – Part 17 (Auto Delete System Generated Chatter Post)

Getting Started with Process Builder – Part 17 (Auto Delete System Generated Chatter Post)

Last Updated on November 30, 2020 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:

  • Create an Auto-Launched flow to delete records
  • Launch a Flow using Process Builder to auto-delete Chatter Posts

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:

Auto generated chatter post He wants to auto delete this post 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 other’s posts. However, many times I have found that people are looking for ways to delete system generated Chatter posts.

In this article, I am going to discuss how to auto-delete system generated Chatter posts. There are several possible solutions. I will help you understand how to auto-delete system generated Chatter posts using Flow, and we will launch the Flow via Process Builder when the Leads gets converted.  

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

  1. Create a custom checkbox field on Lead
  2. Create a custom checkbox field on Account
  3. Map custom lead fields for lead conversion 
  4. Lightning Flow Steps:
    1. Define flow properties for auto-launched flow
    2. Add a text variable to store account id
    3. Add a delete records element to delete system generated post 
  5. Process Builder Steps:
    1. Define process properties
    2. Define evaluation criteria
    3. Define process criteria
    4. Set time for actions to execute
    5. Add action – flows 

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: 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 4.2: Lightning Flow – Add  a Text Variable to Store Account Id

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

Step 4.3: Lightning Flow – Add a Delete Records Element to Delete System Generated Post

  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 Account Feed object from the dropdown list.
  5. Set Filter Conditions
    1. Row 1:
      1. Field: ParentId
      2. Operator: Equals
      3. Value: {!varTAccountId}
  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: 50
  5. Interview Label: Delete system generated post {!$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 Account object to launch a Flow, only when an account is created from lead conversion. 

Step 5.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 5.2: Define Evaluation Criteria

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

Step 5.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: Account | Lead_Conversion__c
      2. Operator: Equals
      3. Type: Boolean
      4. Value: True
  5. Select All of the conditions are met (AND)
  6. Click Save.

Step 5.4: set time for actions to execute

  1. Below Scheduled Actions, click Set Schedule.
  2. Set Field Values:
    1. Row 1:
      1. 0
      2. Hours
      3. After
      4. CreatedDate
  3. Click Save.

Step 5.5: Add Action – Flows

  1. Below 0 Hours After CreatedDate Scheduled Actions, click Add Action.
  2. For Action Type, select Flows
  3. Name the action.
  4. Select Flow – Delete system generated post.
    1. Set Flow variables: 
      1. Row 1
        1. Field: varTAccountId
        2. Type: Field Reference
        3. Value: Account | Id
  5. Click Save.

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

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

Proof of Concept

Now onwards, if a business user converts a lead, Process Builder 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? 

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!

17 thoughts on “Getting Started with Process Builder – Part 17 (Auto Delete System Generated Chatter Post)

  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.