# What is Flow in Salesforce (Process Automation)

Salesforce Flow is an automation tool in Salesforce that allows you to automate complex business processes with minimal or no code. It is used to automate tasks such as data collection, record updates, and decision logic within the Salesforce platform.

**Types of Flows :**

1. **Screen Flow :**
    
    * A flow that provides a series of screens to guide users through a process, such as a wizard for creating or updating records.
        
    * It can be launched through : 1)Lightning page 2)Experience Cloud Sites 3)Quick Actions 4)and more.
        
    * We can add screen flow on record page as well.
        
2. **Record-Triggered Flow :**
    
    * Automatically runs when a record is created or updated, similar to a workflow or Process Builder.
        
    * It is often used to automate actions like updating related records or sending notifications when specific criteria are met.
        
    * It is triggered/launched by a specific event like
        
        * 1. Created record 2) Updated record 3) Deleted record
                
3. **Auto Launched Flow :**
    
    * A flow that runs automatically without user interaction, triggered by a specific event like a record creation or update.
        
    * Often used for automating backend processes such as data updates, record creation, or integrations.
        
4. **Scheduled-Trigged Flow :**
    
    * This flow runs at a scheduled time or interval.
        
    * It is useful for batch processing tasks, like updating records daily or sending reminder emails.
        

### Components of Flow :

1. **Flow Elements :**
    

* **Interaction**
    
    * a)Screens: Display information or collect user input.
        
    * b)Actions: Perform tasks such as creating records, sending email alerts, or submitting for approval.
        
    * c)Sub-Flows: Call another flow within a flow to reuse common functionality.
        
* **Logic**
    
    * a)Assignment
        
    * b)Decision
        
    * c)Loop
        
    * d)Collection Sort
        
    * e)Collection Filter
        
* **Data**
    
    * a)Create Record
        
    * b)Update Records
        
    * c)Get Records
        
    * d)Delete Records
        

2. **Resources that can be created :**
    
    * Variable, constant, Formula, text Template, Choice, Record Choice Set, Picklist Choice set, Stage.
        

---

### When to use Flow ?

* Automate a guided visual experience : Screen Flow
    
* To build complex functionality which can run automatically in background
    
    * Record Triggered Flow
        
    * Scheduled Trigger Flow
        
    * Auto launched flow
        
* Need to call flows from apex or lightning
    

---

# I) Screen Flow

**NOTE *: Screen flow is not specific to the Object.***

* Consider the below scenario to implement the screen flow in salesforce
    

# **Examples to Implement Scenario 1:**

* Create a Screen Flow to Create an **Opportunity** related to an **Account.**
    
* Launch the screen flow through **Quick Action** for Account Record Page.
    
* Place screen flow on Account Record Page.
    

### **Create a Screen Flow to Create an Opportunity related to an Account.**

1. Go to flows and create anew flow from scratch
    
2. Add new screen and add the text field, picklist and date field in the screen
    
3. For populating the values in picklist you can either add the values manually which are present in opportunity picklist or you can populate those values from the opportunity stage picklist. For Populating follow thisClick on Choice→New Resource Choice and then select Picklist choice set. And select the opportunity object and follow the steps.
    
4. Add New **Component Create Record :**
    
    1. Under “How to Select Record Field Values“ Select Manually
        
    2. Under “Create Record of This Object“ Select Opportunity Object
        
    3. And do the field values Mapping
        

### **Launch the screen flow through Quick Action for Account Record Page**

`NOTE : Before this create a “New Resource“ as variable and give API Name as recordId and Data Type as Text and click on "Available From Input” and Map this recordId with AccountId field in Create Record Component`

1. Go to Account Object→Buttons, Links & Action
    
2. Create New Action
    
    1. Select Action Type as Flow
        
    2. Select Flow (the name we gave to our flow will appear if its activated.
        
    3. After creating action place it on record page by navigating in page layout of that object
        

### **Place screen flow on Account Record Page**.

1. Click on gear icon and click edit page. This will open record page in Lightning App Builder.
    
2. Drag Flow Component into the UI
    
3. On Right side of you builder under “Flow” select the proper flow name you created.
    
4. You will be able to see the recordId resource variable which we created earlier to pass the Account Id. There would be a checkbox which states “Pass Record Id Into This Variable“ check this as this will pass the account Id and eventually opportunity and account will be related with each other.
    

# **Examples to Implement - Scenario 2 :**

* Option to attach a File and File Should be related to Contact
    
* Option to Link Contact with an Account
    
* Upon Contact Creation Send an Email
    

### **Option to attach a File and File Should be related to Contact**

1. For uploading file create a new screen below create record.
    
2. The file component need’s **Related Record ID** (that is to which object this file is related).
    
    1. Create a variable name contactId first so that we can use it for relating it with the file.
        
    2. Now open create record and **check** on “**Manually Assign Variable**“ (This means whenever the contacts record is created assign its recordId to our specified variable) and choose the variable which we created.
        

### Option to Link Contact with an Account

1. Note One Account can have Many Contacts associated with it.
    
2. In Flow Builder search “**Lookup**” component, this component allows us to create lookup linking with the source objects.
    
3. After adding Lookup component set it’s properties to do that follow below steps:
    
    1. Set “**Field API Name**“ as **AccountId.** This is the unique Id for Accounts object
        
    2. Set “**Object API Name**“ as **Contact.** This is the object where lookup field is present right. We need to link AccountId with Contact object.
        
4. Finally, Edit “**Create Contact Record”** and map the fields. Set Field as **AccountId** and value as **API** **name** of **Lookup** **Component** we create*d.*
    

### Upon Contact Creation Send an Email

`There are two ways in which you can send email. Email Alert and Email Action. As of now we are user Email Action.`

1. Add “**Email Action”** component below “**Create Contact Record”**
    
2. Under **Email** **Action** properties follow below steps:
    
    1. Set Email Body by creating new resource as Text
        
    2. Set Email Subject.
        
    3. Under Recipient Address Collection you need a collection of Recipient Address.
        
    4. For that Create a new Variable as “**emailAddresses**” and check “**Allow Multiple Values (collection)**“.
        
3. After creating a collection variable use **“Assignment Component”** to assign the value of Email address from Create Contact Screen to this emailAddress collection variable. Add the **Assignment** Component in between **Create Contact Record** and **Email Action.**
    
    1. Under “**Set Variable Values**” select “**Variable**” as **emailAddresses** (collection variable which we created) and “**Operator as add**“ and “**Value”** as Email (This is email text field of the Create Contact Screen).
        
    2. By following thisthe email from text field will be added in the collection variable.
        
4. After that set **Recipient** **Address Collection** as **emailAddress** (Collection variable which we created)
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728543093761/1cd65629-e973-4a8d-849a-51e7eda61486.png align="center")

Refer this flow image for **scenario 2**

**Quick Notes :**

* Email Alerts and Email Actions are not same
    
    * **Email** **Alerts** - Automated, triggered by rules, used mainly in workflows, processes, and approvals.
        
    * **Email Actions**: Manual, initiated by users, used in user interfaces as part of global or quick actions.
        

# Examples to Implement - Scenario 3 :

* Create a Contact OR an Opportunity OR a Case related to Account based on User’s choice through one Flow.
    
* Create a Contact OR an Opportunity OR a Case related to Account based on User’s choice through Sub Flow.
    
* Modify above flow to ask how many Contact OR Opportunity OR Case should be created related to Account based on User’s choice.
    

### Implementation for Scenario 1 and 2

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728552879781/a6f64630-8e73-410e-8d13-d08c367204a0.png align="center")

### Modify above flow to ask how many Opportunity should be created related to Account.

* We can directly use the loop component to do so but we will try to use the existing components such as
    
    1. Variable
        
    2. Assignments
        
    3. Decision Component
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728555969826/f6b80bd4-98f4-4ca4-a06b-3865e7110566.png align="center")

# II) Record-Triggered Flow

**NOTE** : ***Record Trigger Flow are Object Specific.***

* Automatically runs when a record is **created** or **updated**, similar to a **workflow** or **Process** **Builder**.
    
* It is often used to automate actions like updating related records or sending notifications when specific criteria are met.
    
* If you have one **flow** available on particular object and if you want to **maintain** the **order** of their execution then you can use this.
    
* It is **triggered**/**launched** by a specific event like:
    
    1. Created record.
        
    2. Updated.
        
    3. Deleted record.
        
    4. Record is Created or Updated
        

***What is Global Variable, Example :***

* Lets say you are using after save type then there will be a $Record variable where all of the info related to newly created object will be present.
    
* If Account record is created then $Record will have all the info related to the Account Object. For Example - You can access it using “**$Record.id”**
    

# Types of Record-Trigger :

### Fast-Field Update :

* Runs **before** the record is saved to the database.
    
* The flow modifies the fields of the record that triggered it
    
* These flows are ideal for simple updates, like modifying a field value based on a condition (e.g., setting a default value, updating a status based on criteria, or updating the account type).
    
* **Example** : Automatically populating a "Next Follow-Up Date" on a Task when the task is created
    

### Actions and Related Records :

* Runs **after** the record is saved to the database.
    
* Allows for more flexibility, as the flow can interact with related records or even create, update, or delete other records.
    
* Can perform a wide range of actions like:
    
    * Updating related records (e.g., updating all contacts related to an account when the account’s status changes).
        
    * Creating records (e.g., creating a follow-up task when a case is closed).
        
    * Sending email alerts or posting to Chatter.
        
    * Invoking sub-flows or executing Apex code if needed.
        

### Run Asynchronously :

* **Run Asynchronously** in a **Record-Triggered Flow** allows the flow to perform actions **after** the initial transaction completes, running those actions in the background without blocking the main transaction.
    
* This means the record is saved to the database first, and then the flow actions (e.g., updates to related records, sending notifications, or making callouts) are processed in the background, independently of the main transaction.
    

***Example Scenario for Run Asynchronously:***

* Imagine you have a Record-Triggered Flow that needs to update thousands of related records when an account's status changes.
    
* If you run this synchronously, it may cause performance issues or hit limits like the DML limit. By choosing to run asynchronously, the flow can process these updates in the background, ensuring the main transaction (saving the account) completes quickly without delays.
    

### Scheduling Paths :

* It is used for Scheduling reminders or follow-ups based on dates in the record that **triggered** the **flow**, such as Close Date.
    
* Benefit: Waits a specified amount of time between the trigger firing and the automation running.
    

# Examples to Implement - Scenario 1 :

* On Account Creation if Industry = ‘Media‘ then populate Rating as ‘Hot‘.
    
* Upon creation of an account a related Opportunity should be created automatically (**Criteria** : If ‘Active‘ = Yes on account then only new opportunity should be created)
    
    * Opportunity Name = Account Name
        
    * Close Date = Today
        
    * Stage = Prospecting
        
* When a **contact** is created then update the “**Total Contact**” field on **Account** by using **Record-Triggered** Flow
    

### On Account Creation if Industry = ‘Media‘ then populate Rating as ‘Hot‘.

* You can try this example at your end
    

### Upon creation of an account a related Opportunity should be created automatically

***Criteria*** *: If ‘Active‘ = Yes on account then only new opportunity should be created*

* You can try this example at your end
    

### When a **contact** is created then update the “**Total Contact**” field on **Account** by using **Record-Triggered** Flow

**Note** : Here **Contact** is child object and **Account** is Parent Object (There is **Lookup relationship** between them).

*Basically in this* ***Scenario*** *we are creating* ***child*** *record and through that we are updating* ***parent*** *record.*

# Examples to Implement - Scenario 2

* Upon Account Phone Update, update all related contacts phone number as well.
    
    * Without using loop element
        
    * With using loop element
        

### Upon Account Phone Update, update all related contacts phone number as well.

`Record-Trigger Type : (Actions and Related Records)`

**Implementation Without using loop element**

* Select Object as : **Account**
    
* Select Configure Trigger : A record is updated
    
* Set Entry conditions as none
    

After setting the Record-Trigger Starting properties add **Update Records** Component to the flow.

* In update record under “**How to Find Records to Update and Set Their Values**“ select “**Specify conditions to identify records, and set fields individually” .**
    

This option will allow us to choose the Object which we want to update and will allow us to filter the records by specifying the criteria and will allow us to set the fields which we want to update.

* Under “**Update Records of This Object Type”** select “**Contact”** Object.
    

This option allow us to choose which object we want to update

* Under “**Filter Contact Records**“
    
    * select Filed as **AccountId(Contact Object filed),** Operator as **Equals**, Value as **$Record.id (Account Object field).**
        

This option allow us to get the specific contact details according to the conditions which we have provided.

* Under **“Set Field Values for the Contact Details“** set Field as **Mobile Phone (Contact Object Field)**, Value as **$Record.AccountPhone (Account Object Field Value).**
    

This option will set the **Mobile Phone** Field value of each contact as the value of **Phone Number** of Account Object which we provided.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728640539766/39823801-d75e-416d-a9d2-5acaab0e913a.png align="center")

---

**Implementation Using Loop:**

* In order to use loop the logic goes like this.
    
* Get All Contacts → Loop Over the Contacts → Assign each Contact to a Contact Record Variable (Using Assignment Component) → Add Contact Record in Contact List (Using Assignment Component).
    
* At the end use **Update Records** Component. Under “**How to Find Records to Update and Set Their Values”** choose **Use the IDs and all field values from a record or record collection.**
    
* Under “Select Records to Update” select the Collection list which we created (Contact Record List).
    

By following 3rd and 4th step it will use the id’s provided in Contact Record Collection to search the contact and will update the fields which are present in the collection.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728640495018/1cd518aa-81d4-4305-a916-c597108e43de.png align="center")

# Record Trigger Components

1. **Update Records :**
    
    * By using this component we can update the record. There are 4 options to find the records and update in this component.
        
        * **Use the account record that triggered the flow**
            
        * **Update records related to the Current Object record that triggered the flow :**
            
            * That means the object which triggered the flow it’s related accounts will be updated. So you need to specify which is the related object and set the field values to update.
                
        * **Use the IDs and all field values from a record or record collection**
            
        * **Specify conditions to identify records, and set fields individually :**
            
            * If we choose this we need to select object to update and if we want we can add filter to choose which records to update. That is we can add criteria to only find the record and update it with the fields values we will set in this.
