Use Flow Builder to Create a Roll Up Summary Field shares how to calculated related records without using the “Roll Up Summary” field type. It’s useful especially when the two objects don’t have a parent-child relationship.
But this video doesn’t work for deleted records, the process will be triggered only when a child record is created or edited. You need to change the counting criteria, business process, and object permission.
What’s in the Video
In a quick glance:
- Create a flow to calculate the sum of project records with a given account ID.
- The flow also updates the field “project_count_total__c” in the account record.
- Create a process which will be triggered when a project record is created or edited.
What’s the Issue
It works perfectly when a new project record has been created or updated.
When you delete a project record, no process will be triggered. The “project_count_total__c” field won’t be updated.
What’s in the Real-World Business Process
For any sensitive records, I will let the user add a mark for deletion. Usually is to change the status to “Delete”. I won’t let them delete on their own. It prevents data loss and accident.
Only the system admin and/or certain users will have the capability to delete these records.
Besides, each project has a status. When users ask for the summary field, they mean projects in a certain status. They call it a sense of business and won’t explain explicitly. It’s better to define and explain in the balloon help of the field.
How to Implement in Salesforce.com
The key is to use the mark for deletion to replace delete permission. Every record needs to add a mark for deletion before delete.
Mark for Deletion
I will add “Delete” as a new picklist value in the status-or-like field. Or create a new checkbox field. The later will need to change the existing layout and is not suggested.
Change the criteria when you get the records to exclude those mark for deletion.
In this video, I will add it in the “Filter Project Records” while creating a “New Get Records” at 1:42.
Remove Object Delete Permission in User Profile
Remove the “Delete” permission on the object in all user profiles. Sometimes there are superusers to have the delete permission.
Delete Records with Mark for Deletion
The Salesforce Admin and/or the superusers will need to clean up records which have the mark for deletion regularly. It could be done by deleting manually or running an Apex script.
It’s a good idea to schedule an Apex to run automatically.