# Flow & Process Automation

> Flow types, before-save vs after-save, building common automations and choosing Flow or Apex.

**Track:** admin · **Category:** Automation · **Topics:** Flow, Automation, Approval process

Read on the site: https://www.forcechallenges.com/notes/flow-automation

**Flow** is Salesforce's main declarative automation tool. Workflow Rules and Process Builder are retired for new automation — migrate them to Flow.

## Flow types

| Type | Starts when | Example |
|---|---|---|
| **Record-triggered** | A record is created/updated/deleted | Default a field, create a task |
| **Screen** | A user launches it (button, page, action) | Guided wizard |
| **Schedule-triggered** | On a schedule | Nightly clean-up |
| **Autolaunched** | Called by Apex, another flow, REST | Reusable logic |
| **Platform event–triggered** | An event is published | React to integrations |

## Record-triggered: before-save vs after-save

| | Fast Field Updates (before save) | Actions and Related Records (after save) |
|---|---|---|
| Updates the triggering record | ✅ very fast, no extra DML | possible but costs a DML + re-save |
| Create/update **other** records | ❌ | ✅ |
| Send emails, call subflows/actions | ❌ | ✅ |
| Record Id available on create | ❌ | ✅ |

## Example 1 — default a Rating (before-save)

*Object:* Account · *Trigger:* created · *Optimize for:* Fast Field Updates

1. **Decision**: `AnnualRevenue >= 1,000,000` → *Hot*; `>= 100,000` → *Warm*; default → *Cold*.
2. **Assignment**: `{!$Record.Rating}` = the chosen value.

No Update Records element is needed — changes to `$Record` are saved automatically.

## Example 2 — mark the Account a Customer when an Opportunity is won (after-save)

*Object:* Opportunity · *Trigger:* updated · *Entry condition:* `StageName = Closed Won` · **Only when a record is updated to meet the condition**.

1. **Update Records**: Account where `Id = {!$Record.AccountId}` → `Type = Customer`.

The "only when updated to meet the condition" option is the declarative version of comparing `Trigger.old` and `Trigger.new`.

## Best practices

- Keep **one or few** record-triggered flows per object and use **entry conditions** and **trigger order**.
- Never put **Get/Update/Create Records inside a Loop** — collect into a collection variable and update once (same bulkification rule as Apex).
- Add **fault paths** to handle errors.
- Use **subflows** for reusable logic.

## Flow or Apex?

| Choose Flow when | Choose Apex when |
|---|---|
| Logic is simple to moderate | Complex logic, heavy data volumes |
| Admins will maintain it | Callouts with complex parsing, advanced error handling |
| Field updates, records, emails, approvals | Precise control of transactions, unit tests, reuse in APIs |

## Approval processes

Multi-step sign-off (e.g. discounts > 20%) with entry criteria, approvers (manager, queue, user), approval/rejection actions and record locking.

## Interview questions

1. *Before-save vs after-save flow?*
2. *How do you avoid hitting limits in a flow loop?* → No DML/queries inside loops; use collections.
3. *How do you make a flow run only when a field changes to a value?* → "Only when a record is updated to meet the condition requirements".
4. *When would you pick Apex over Flow?*

---
Source: ForceChallenges · last updated 2026-10-03
