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 in not enabled. First of all, I would like to say thanks to Mr. Chris Whitehead for asking such a great question on Success Community.
First of all, you have to understand the Feed table 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 name of the related standard object. 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 a case with the custom object. If Feed tracking is turned off for a custom object, then CustomObject__Feed object will not be available. So you can’t use CustomObject__Feed object to delete the posts (On parent object) generated from Quick Actions. So how to delete then ??? Let’s start with a business use case
Business Use case
Rachel Gillett is working as System administrator at Universal Containers (UC). At UC they have created a custom object called as 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 Account object, and Feed tracking is turned off for Time Sheet object. Rachel has received a requirement from the management when a Sales rep creates a Time Sheet from Account object using quick action, system auto-generates a chatter post similar to the following screenshot
They want to auto delete post generated from Quick Action.
Solution for the above business requirement
First of all, we will use Flow to delete system generated Chatter post. To launch a Flow whenever Time Sheet gets created, we will use Process Builder. Follow the below instructions to create a Process Builder and Flow to solve the above business requirement
1. First of all create a custom object (Time Sheet) and few fields to store the data, as shown in the following screenshot
Make sure that you have turned off Feed tracking for Time Sheet object. Also, remove Quick_Action__c field from the page layout.
2. To create object specific action on Account, navigate to Setup | Build | Customize | Accounts | Buttons, Links, and Actions and click on the New Action Button. Now create an action that allows users to create a new Timesheet as shown in the following screenshot
Make sure that you have added the fields mentioned in the following screenshot to quick action layout
3. 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
4. The next step is to create a Flow, navigate to Name | Setup | App Setup | Create | Workflows & Approvals | Flows
5. Click on New Flow, it will open the Flow canvas for you. Now create a Text variable VarT_TimeSheetId to store the Time Sheet Id (we will pass the Time Sheet Id through Process Builder), as shown in the following screenshot
6. The next step is to delete the post generated from Quick Action. To do this drag-and-drop Record Delete element (Enter the name Delete posts generated from Quick Actions) onto the canvas and map the fields according to below details
- Select object FeedItem
- For criteria select ParentId= {!VarT_TimeSheetId}, as shown in the below screenshot
7. Finally, your Flow will look like the following screenshot
8. Save your Flow with name Delete Quick action feed and close the canvas. Don’t forget to Activate the Flow.
Launch a Flow from Process Builder
Our next task is to create a Process Builder on the Time Sheet object to launch a Flow. To create a Process Builder on the Time Sheet object follow the below instructions
1. Click on Name | Setup | App Setup | Create | Workflows & Approvals | Process Builder
2. To create a new process from scratch, click on the New Button available on Process Management page. A popup will appear where you have to enter the Name (Use Delete Unaccepted Quotes as name), API Name and Description as shown in the below screenshot
3. Click on Object node to add object and then select Time Sheet object. For the entry criteria, Select only when a record is created, as shown in the below screenshot. Once you’re done click on the Save button
4. The next task is to add Process Criteria, To do this click on Add Criteria, enter Name, Type of action and set filter conditions (In this case set [Time_Sheet__C].Quick_Action__c Equals True) and click on the Save button as shown in the following screenshot
5. The next step is to set the time for schedule action. For this click on Set Schedule available under Scheduled actions. Set time for scheduled actions as shown in the following screenshot
6. Now we have to add a Time-based action into the Process to launch a Flow. Click on Add Action (Under Scheduled actions), Select the type of action to create (In our case Flows) and then fill out the fields to define the action as shown in the following screenshot
7. Once you are done, click on the Save button, it will redirect you to Process canvas. Finally, the Process will look like the following screenshot
Don’t forget to active the Process by clicking on the Activate button.
It’s time to test this feature
1) 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
2) Wait a few seconds and then reload the account page.
Note: – I will suggest you to implement this first on your developer org, test it and then move it to production.