Last Updated on November 30, 2020 by Rakesh Gupta
Big Idea or Enduring Question:
How do you automatically delete posts generated from quick actions?
A few months back, I had written an article Getting Started with Process Builder – Part 17 (Auto Delete System Generated Chatter Post) to discuss a way through which, we can auto-delete system generated Chatter posts. This article goes a step ahead and explains, how to auto-delete posts generated from Quick Actions for objects in which Feed Tracking is not enabled.
Objectives:
After reading this article, the reader will be able to:
- Using Process Builder to auto-delete system-generated chatter posts
- How to use get the delete element to delete records
- How to Launch a Flow from Process Builder
Business Use case
Rachel Gillett is working as a System administrator at Universal Containers (UC). At UC they have created a custom object called Time Sheet, to allow their sales reps to enter the time they spent at a customer site (i.e. against Account object). The Time Sheet object has a lookup relationship with the Account object, and Feed tracking is turned off for the Time Sheet object. Rachel has received a requirement from the management when sales reps create a Time Sheet from an account object using quick action, the system auto-generates a chatter post similar to the following screenshot:
Business wants to auto-delete posts generated from Quick Action.
Automation Champion Approach (I-do):
First of all, you have to understand the Feed object in Salesforce. All objects have a default related Feed object. All Feed objects for custom objects are named as CustomObject__Feed, where CustomObject__c is the name of the related custom object. All Feed objects for standard objects are named as LeadFeed, where Lead is the related standard object name.
But the glitch is Feed object is by default available (You can access it from the API or Flow) for a standard object, even though Feed Tracking is turned off, but that is not the case with the custom object. If Feed tracking is turned off for a custom object, then the CustomObject__Feed object will not be available. So you can’t use the CustomObject__Feed object to delete the posts (On parent object) generated from Quick Actions.
There are a few possible solutions for the above business scenario, but I’ll use Process Builder and Flow to solve the business requirement.
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.
Guided Practice (We-do):
There are 4 steps to solve Rachel’s business requirement using Flow and Process Builder. We must:
- Create a custom object that will be used to store Time Sheet
- Create a quick action on the Account object to create a timesheet record
- Lightning Flow Steps:
- Define flow properties for auto-launched flow
- Add a Text variable to store time sheet Id
- Add a Delete Records element to delete system generated Chatter post
- Process Builder Steps:
- Define process properties
- Define evaluation criteria
- Define process criteria
- Set time for actions to execute
- Add action – flows
Step 1: Create a Custom Object
The next step is to create a custom object Time Sheet and a few custom fields to store timesheet related information:
- Click Setup.
- In the Object Manager, click Create | Custom Object.
- Now create a custom object Approver Matrix and fields as shown in the screenshot below:
- Click Save.
- Make sure that you have turned off Feed tracking for the Time Sheet object. Also, remove the Quick_Action__c field from the page layout.
Step 2: Create a Custom Quick Action to Create Time Sheet Record
When you create actions, you can use predefined field values to set a value for a field. Predefined values can help ensure consistency and make it faster and easier for users to create records. Now set a Predefined value for Time Sheet object’s field Quick Action as True, as shown in the following screenshot
- Click Setup.
- In the Object Manager, type Account.
- Select Button, Links, and Actions, then click New Action.
- For Action Type select Create a Record.
- For Target Object select Time Sheet.
- Enter Field Label and click the Next button. The API Name will populate.
- As a best practice, always input a description.
- Click Save.
- Make sure that you have added the following fields mentioned in the following screenshot to the quick action layout.
- When you create actions, you can use predefined field values to set a value for a field. Predefined values can help ensure consistency and make it faster and easier for users to create records. Now set a Predefined value for Time Sheet object’s field Quick Action as True, as shown in the following screenshot
Step 3.1: Lightning Flow – Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- Click Done.
Step 3.2: Lightning Flow – Add a Text Variable to Store Time Sheet Id
- Under Toolbox, select Manager, then click New Resource to store time sheet record Id.
- Input the following information:
- Resource Type: Variable
- API Name: varTTimeSheetId
- Data Type: Text
- Default Value: {!$GlobalConstant.EmptyString}
- Check Available for Input
- Check Available for Output
- Click Done.
Step 3.3: Lightning Flow – Add a Delete Records Element to Delete System Generated Chatter Post
The next step is to delete the post generated from Quick Action. To do this drag-and-drop Record Delete element.
- Drag-and-drop Delete Records element onto the Flow designer.
- 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 Feed Item object from the dropdown list.
- Set Filter Conditions
- Row 1:
- Field: ParentId
- Operator: Equals
- Value: {!varTTimeSheetId}
- 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: 50
- Interview Label: Update Sync Quote {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Our next task is to create a Process on the Time Sheet object to launch a Flow, only when a timesheet record is created.
Step 4.1: Define Process Properties
- Click Setup.
- In the Quick Find box, type Process Builder.
- Select Process Builder, then click New.
- Name the Process and click the Tab button. The API Name will populate.
- As a best practice, always input a description.
- The process starts when A record changes.
- Click Save.
Step 4.2: Define Evaluation Criteria
- Click on the Add Object node to begin selecting the evaluation criteria.
- Select the Time Sheet object from the dropdown list.
- Start the process when a record is created or edited.
- Click Save.
Step 4.3: Define Process Criteria
- Click the Add Criteria node to begin defining the process criteria.
- Name the criteria.
- The criteria should execute actions when the conditions are met.
- Set Conditions
- Row 1
- Field: Time Sheet | Quick_Action__c
- Operator: Equals
- Type: String
- Value: True
- Row 1
- Select All of the conditions are met (AND).
- Click Save.
Step 4.4: set time for actions to execute
- Below Scheduled Actions, click Set Schedule.
- Set Field Values:
- Row 1:
- 0
- Hours
- After
- CreatedDate
- Row 1:
- Click Save.
Step 4.5: Add Action – Flows
- Below 0 Hours After CreatedDate Scheduled Actions, click Add Action.
- For Action Type, select Flows.
- Name the action.
- Select Flow – Delete system generated chatter post.
- Set Flow variables:
- Row 1
- Field: varTTimeSheetId
- Type: Field Reference
- Value: Time Sheet | Id
- Row 1
- Set Flow variables:
- 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
Now onwards, if a business user creates a timesheet record by using the quick action, 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.
- Navigate to the Account tab, identify the Account, and click on the Account Name. Create a new Time Sheet record using quick action that we have created, as shown in the following screenshot:
- Wait a few minutes and refresh the Account detail page.
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.