Skip to main content

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.

Formula
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:

Formula
Fee__c * 1.18

Flow: 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 typeStarts whenExample
Record-triggeredA record is created, updated or deletedWhen an enrolment is paid, mark the student active
ScreenA user launches it from a page, button or appA guided form that registers a walk-in student
ScheduledAt a set time, for a batch of recordsEvery morning, remind students whose fee is due
AutolaunchedCalled from another flow, Apex or a platform eventReusable 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 forUpdating fields on the same recordCreating or updating other records, sending emails, calling actions
SpeedFastest; no extra saveSlower; runs after the record is committed to the database
ExampleSet Level__c from the hours enteredCreate a welcome task for the course coordinator
What happens when an enrolment is saved

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

  1. 1.Which tool should you use to make sure an opportunity cannot close without a loss reason?
  2. 2.Which flow type guides a user through a form with several steps?
  3. 3.A flow must create a task on another object when a record is saved. Which record-triggered option fits?
0 of 3 answered

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.