Keep Salesforce Data Clean With Before Save Flows
Data quality is essential for every Salesforce administrator, as it influences reporting accuracy, decision-making, and overall user confidence. With users constantly inputting data through multiple interfaces, maintaining clean, standardized field values is an ongoing challenge. Fortunately, Salesforce provides tools like validations, reports, batch updates, workflow rules, and processes to help manage data consistency. The introduction of before-save flows in the Spring â20 Release has transformed data handling, allowing admins to update field values as records are created or modifiedâwithout needing complex code. This guide will explore how before-save flows can help streamline data entry, reduce errors, and ensure clean, accurate field values across all data channels.
There are several tools available in Salesforce to ensure clean data:
- Validations
- Reports
- Batch updates
- Workflow rules
- Flows
- Code
Salesforce administrators have the functionality to update field values by triggering a before-save flow when a record is created and/or updated. Admins do not need to write code to start the update.
Understanding The Before-Save Flow Execution
Before we go into the details of the use case and the solution, letâs dissect and understand what this all means. When a user creates or updates a record there are several steps that are executed while the data is being written to the database. When we use popular automation tools and trigger an update on the fields, what typically happens is that the data the user provides is saved, and then overwritten based on the automation rules that are implemented in the system. This update method is not very fast, and presents several potential complications: Duplicate rules can kick in based on the data that is initially entered into the system and produce unexpected results, although the final data saved based on the active automation rules may not trigger the same duplicate rule.
Advantages of Before-Save Flow Updates
Before-save updates are executed before the data is saved; very early in the order of execution. This makes them very fast, and also more predictable because there is a lower chance that they produce unexpected results interacting with other automation rules.
Another advantage of before-save updates is that they are executed regardless of what channel the update is coming from. You may have internal users entering data on Salesforce. You may also have external users entering data on a flow that runs on a digital experience (community) site. If you use field validation rules, you will need to set them up separately on all channels. When you set up a before-save flow update, on the other hand, it will be executed whenever the data is entered and/or updated regardless of the channel.
Examples of Before-Save Flow Applications
đ¨ Use Cases đđź What is this solution good for?
- Clean special characters from phone field entry on the contact
- Update custom record name combining several field values on the same object
- Update accounts based on employee count and categorize them by Small/Medium/Large
Main limitations:
- The flow operations that can be performed are limited (please see the image).
- Before-save flows can not perform create or update operations on the related objects and their fields.
Clean Special Characters From Phone Entry
I built a solution for volunteers to check-in on a digital experience site using their mobile phone number. One potential issue with this flow is that the users enter phone numbers into the system in various formats. For example, these entries are very common:
- 5555555555
- 555 555 55 55
- (555) 555-5555
You can easily write a SUBSTITUTE formula to strip the special characters and spaces out of these entries.
This means that you can build a very simple formula to take the phone data entry value, and replace it with a new value before it is committed to the database. The new value will be in the format of the first bullet above.
The Flow
Start a record-triggered before save flow.
The flow consists of two elements only: The start element and one assignment element. Please remember that there is no need for a get or update element. We are working with the value that is entered on the screen and assigning a value to what will be written to the database.
Please note that I recommend using the update element before save instead of the assignment element currently, although the functionality is the same.
The flow is short and simple.
The first step on our flow will be to adjust the settings on the start element. When the start element is double-clicked, the flow editor displays several settings that can be adjusted. In this example, we would like to launch our flow when a contact record is created or updated to make fast field updates.
The second element in the flow is a simple assignment element. {!Record.MobilePhone} refers to the mobile phone field on the contact record that the user is about to create or update. This step assigns a formula value to the mobile phone field.
The Formula
Here is the {!CleanMobilePhone} formula:
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE({!$Record.MobilePhone} , "(", ""), ")", ""), " ", ""), "-", "")
It is a simple formula that finds the ()- and space characters in a string and removes them.
The Result
When this flow is saved and activated, it updates all mobile phone entries before they are saved to the database. The field value will only consist of digits. Please remember that Salesforce formats the phone fields for display purposes on the screen. You will see (555) 555-5555 displayed on the screen, but when you go to edit the field, you will find out that the value only includes digits.
Enjoy.
Explore related content:
Popular Validation Rules for Salesforce Flows including Phone, Email and Address Fields
6 Things You Can Do With The Transform Element
Create by Checking a Matching Record in Flow
#Administrator #Applications #Automation #BeforeSave #Developer #FieldValues #Formula #HowTo #Salesforce #SalesforceTutorials #UseCases