Lesson 4 of 5 16 min read
Automating work with Flow
Keep data clean with validation rules and formula fields, then automate business processes with record-triggered, screen and scheduled flows.
In this lesson you will
- Write validation rules and formula fields
- Choose the right type of flow for a business requirement
- Explain before-save and after-save record-triggered flows
Start with clean data
Validation rules stop bad data from being saved. A validation rule is a formula that describes invalid data: when it evaluates to TRUE, the save is blocked and your error message appears.
AND(
ISPICKVAL(StageName, "Closed Lost"),
ISBLANK(Loss_Reason__c)
)This rule makes users enter a loss reason before marking an opportunity Closed Lost.
Formula fields calculate a read-only value whenever the record is viewed, so they never go out of date:
Fee__c * 1.18Flow: automation without code
Flow is Salesforce's automation tool. You build logic visually in Flow Builder with elements such as Get Records, Decision, Assignment, Update Records and Send Email. Salesforce recommends Flow for all new declarative automation; the older Workflow Rules and Process Builder are retired.
| Flow type | Starts when | Example |
|---|---|---|
| Record-triggered | A record is created, updated or deleted | When an enrolment is paid, mark the student active |
| Screen | A user launches it from a page, button or app | A guided form that registers a walk-in student |
| Scheduled | At a set time, for a batch of records | Every morning, remind students whose fee is due |
| Autolaunched | Called from another flow, Apex or a platform event | Reusable logic such as calculating a discount |
Before save or after save?
A record-triggered flow runs either before or after the record is saved:
| Fast Field Updates (before save) | Actions and Related Records (after save) | |
|---|---|---|
| Best for | Updating fields on the same record | Creating or updating other records, sending emails, calling actions |
| Speed | Fastest; no extra save | Slower; runs after the record is committed to the database |
| Example | Set Level__c from the hours entered | Create a welcome task for the course coordinator |
User sends to Salesforce: save an Enrollment__c record. Salesforce sends to Salesforce: before-save flow sets fields. Salesforce sends to Database: commit the record. Salesforce sends to Salesforce: after-save flow checks: fee paid?. Salesforce replies to User: contact updated, welcome email sent
Test and debug
Use Debug in Flow Builder to run a flow with test values and watch each step. Activate a new version only when it is tested, and add a fault path to elements that can fail, so users see a helpful message and an admin is notified.
Hands-on exercise
Add a validation rule to your Course object so that the Fee cannot be negative. Then build a record-triggered flow on Enrollment that runs after a record is created and creates a task for the course owner titled "Welcome new student". Use Debug to test the flow before you activate it, and then create an enrolment to see it run.
Knowledge check
3 questions • 70% to pass • Practice only, no certificate
Key concepts
- Validation rules block saves when their formula is TRUE; formula fields calculate read-only values.
- Flow is the recommended tool for declarative automation; Workflow Rules and Process Builder are retired.
- Record-triggered, screen, scheduled and autolaunched flows start in different ways.
- Use before-save flows for same-record field updates and after-save flows for related records and actions.
