Lightning Flow

Choose the Right Automation Tool

List the tools included in Lightning Flow. Describe the tools available for automating guided visual experiences. Describe and compare the tools available for behind-the-scenes automation. Describe the tools available for approval automation.
  • Lightning Flow provides a declarative way to automate process for every Salesforce app, experience, and portal. It consists of two tools:
    • Process Builder: lets you build processes
    • Flow Builder: lets you build flows
    • Both tools look like configurable process flow diagrams
  • Example use cases for lightning flow
    • Create a guided tutorial or wizard with screens
    • Set up automated tasks and processes
    • Connect to external systems - communicate changes between Salesforce and external systems with platform events
    • Add automation to pages and apps - examples: lightning pages, community pages, utility bar in lightning apps
    • Reuse what you build - any flow can be used as a subflow, an invocable process can be create to reuse that process’s logic/actions in other processes
  • Three general types of Business Processes
    • Guided Visual Experience: processes that need user input
      • Flow Builder
    • Behind-the-scenes Automation: processes where user input isn’t needed, where all necessary data comes from Salesforce org or a connected system
      • Process Builder, Flow Builder, Apex
    • Approval Automation: example: time-off request that gets approved by the right stakeholders
      • Approvals (not part of lightning flow, but lightning flow does support automating how a record gets submitted for approval)
  • Three tools for admins and developers to choose from:
    • Process Builder: when you need to start a behind-the-scenes business process automatically. Can start when:
      • A record is created or updated
      • A platform event occurs
    • Flow Builder: used to:
      • Automate a guided visual experience
      • Add more behind-the-scenes functionality than is available in Process Builder. Can create the flow, then call it from the process.
      • Start a behind-the-scenes business process, when
        • user clicks a button
        • record created/updated
        • platform event occurs
        • a specified time or frequency has passed
    • Apex: build invocable Apex methods and call them:
      • As an Apex action in the process or
      • As an Apex action element in the flow
  • Scenarios:
    • Guide community member through a wizard: Flow
    • Sales rep clicks a button on an opportunity, launching a discount calculator: Flow
    • When an account is updated, update all contacts related to the account: Process or Flow
    • When an opportunity changes stage, update a custom checkbox: Process or Flow
    • Create a task when a platform event occurs: Process or Flow
    • Update a lead after a certain amount of time passes: Process
    • When an opportunity is won, the company wants a renewal opportunity to be created automatically: Flow
    • Employee requests time-off, manager needs to approve: Approval Process
    • Guide customers through process of troubleshooting issues with a product: Flow Builder
    • When a discount on an opportunity > 40%, notify CEO via email and request sign-off with a way for CEO to comment: Approvals
    • When Annual Revenue > $500,000 on an account, update Customer Priority field to High: Process or Flow
  • Process Builder and Flow Builder should be used before Workflow Rules
  • Generally speaking, try to solve problems declaratively before resorting to Apex code

Automate Simple Business Processes with Process Builder

List the types of processes that you can build in Process Builder. Define the key components used to create a process. Build a process that updates the addresses for an account's contacts when the account’s address is updated.
  • Common use case
    • If an opportunity is created or updated (trigger) and it’s high-value and closed won (criteria), then create a draft contract (immediate action). Six days after the opportunity closes (schedule), create a follow–up task for the account owner (scheduled action).
  • Access process builder via: Setup » Quick Find » “Process Builder” » Process Builder » New
  • Process Builder is a tool that lets you easily automate if/then business processes and see a graphical representation of your process as you build.
  • Components of a process:
    • Trigger: identifies when a process should run. Determines which object and which type of change the process should watch for:
      • Record creation
      • Record creation or update
    • Criteria (1+): determines whether or not to execute actions. If the record doesn’t meet the criteria, the process skips those actions. Each criteria can:
      • Set filter conditions
      • Enter a custom formula
      • Opt out of the criteria
    • Actions: what the process should do.
      • Execute immediately or at a scheduled time.
      • Examples:
        • Create records
        • Update record that started the process or any related record
        • Submit record for approval
        • Update one or more related records
        • Set emails
        • Post to a Chatter feed
  • Process Types: main difference between these is the trigger: when the process starts.
    • Record Change: Process starts when a record is created or edited.
    • Invocable: Process starts when its called by another process.
    • Platform Event: Process starts when a platform event message is received.
  • Tip: plan out business process before you try to automate it. This makes it easier to configure using automation tools.
  • Detailed explanations of the UI available here
  • Example: Keep Contact Mailing Addresses in Sync with Accounts They Belong To
    • Use Process Builder to create a process on the Account object that updates child Contact addresses when an account’s shipping address is updated.
    • Solution here

Guide Users Through Your Business Processes with Flow Builder

Define a flow and list its key components. Describe the types of flow elements. Build a flow that creates a record and uploads files.
  • Access Flow Builder via: Setup » Quick Find » “Flows” » Flows
  • Three distinct flow-related Salesforce terms:
    1. Lightning flow - overall product that includes building, managing, running flows and processes
    2. Flow Builder - point-and-click tool for building flows
    3. Flow - application that automates a business process by collecting data and doing something in the org or external system
  • Other retired flow-related products:
    • Cloud Flow Designer has been replaced by Flow Builder
    • Visual Workflow has been superseded by Lightning Flow
  • Flow Building Blocks - each flow is made up of three building blocks:
    1. Elements - drag from the toolbox
    2. Connectors - define path the flow takes
    3. Resources - containers that represent a given value, like field values or formulas
  • Four types of Elements:
    1. Screen - display data to users or collect info from them
    2. Logic - control the flow, includes branches, update data, loop over sets of data, wait for a certain amount of time, etc.
    3. Actions - do something in Salesforce, such as look up, create, update, delete records, submit records for approval, send email
    4. Integrations - connect to an external database using a core actions or Apex actions
  • Example steps required to create a flow to streamline account creation:
    1. Setup » Quick Find » “Flows” » Flows
    2. Add a Screen to Collect User Input
    3. Add a Create Records Element to Create Records
    4. Create the Screen that Enables File Uploads
    5. Connect the Elements to Finish the Flow
    6. Make Flows Look Like Lightning
      • Two available runtime experiences, Lightning runtime looks like Lightning
      • Setup » Quick Find » “Automation” » Process Automation Settings » Enable Lightning runtime for flows
    7. Distribute Your Flow
    8. Activate Your Flow
      • Only active flows are available in the lightning app builder
    9. Add Your Flow to the Home Page
      • Create a Home Page via: Setup » Quick Find » “Builder” » Lightning App Builder » New » Home Page
    10. Make Sure Your Users can Run the Flow
      • “Run Flows” user permission must be set in the permission set or profile
  • A “Flow Interview” is a running instance of a flow. Users interact with individual interviews of a flow.

Combine the Power of Process Builder and Flow Builder

Describe a business process that can be automated using a process and a flow. Define what a flow variable is. Build a flow that iterates over a group of records. Build a process that starts a flow.
  • Process Builder can’t perform some actions, including:
    • Post to a community feed,
    • Submit a related record for approval,
    • Delete records,
    • Create a bunch of records and associate them with one another,
    • Perform complex logic
      • Best workaround is to configure any more complex functionality in a flow, and then add a flow action to your process. If even a flow isn’t sufficient, Apex code may be required.
  • Suppose you’ve been asked to auto-create renewal opportunities when an opportunity is Closed Won.
    • Process Builder can clone records, but it cannot also clone the products and associate them with the renewal opportunity.
    • Process Builder also cannot take the ID of the created record and use it. Flows can.
    • Solution: Build a flow that clones the opportunity and its products, and build a process that calls the flow when an opportunity closed won.
  • Screen Flows guide users through a business process with screens.
  • Autolaunch Flows run in the background like a process, but cannot have screens. Autolaunch flows can be called from backend things like processes and Apex classes.
  • Flow variables come in four types:
    • Variable: store a single value
    • Collection Variable: store multiple values of the same data type
    • Record Variable: store a set of field values for a single record
    • Record Collection Variable: store a set of field values for multiple records of the same object type
  • The only way to update items in a collection is to iterate over the collection with a loop.
    • In the worked example, each opportunity product in the {!oppProducts_Original} record collection should be associated with the renewal opportunity, and the total prices should be set to null.
      • Tip: Avoid adding actions, like creating/updating records, inside a loop. This is likely to hit resource limits.
  • Among other possible examples, the following use cases would be appropriate for a combination of a process and a flow:
    • Cloning a record and its children,
    • Deleting a related record
  • Visit this trailhead module for other specifics and diagrams.

Customize How Records Get Approved with Approvals

Define an approval process, and list its key components. Describe a business process that can be automated using an approval process. Set up an approval process to automatically manage when an account changes from a prospect to a new customer.
  • An approval process automates how Salesforce records are approved in an org. Two items must be specified:
    1. Steps necessary for a record to be approved. Who approves at each step?
    2. Actions to take based on what happens during approval process. If approved, fields on record are updated. If rejected, send notification to employee.
  • Typical steps in an approval process:
    • Initial submission - default initial submission action is to lock the record, preventing other users from changing the record while it is pending approval. Other possible actions:
      • Sending an email alert,
      • Updating a field on a record,
      • Creating a task,
      • Sending an outbound message.
    • If the next approver rejects the request, final rejection actions are executed. This includes setting the record’s approval status to rejected.
    • If the next approver approves the request, the request moves to the next approver. If all approve, then the approval status on the record is changed to approved, the record is unlocked for future updates, and the employee who submitted the request is notified.
  • Tip: plan out the approval process before you try to automate it. Doing so makes it easier to configure.
  • Setting up approvals on an object may require new fields to be added, such as an Approval picklist with Approved, Not Approved as possible actions.
  • Access the approval processes via: Setup » Quick Find » “Approval” » Approval Processes
  • Note that approval processes must be activated
  • One of the available process actions in Process Builder is Submit for Approval, which means you can build a process that automatically submits records for approval. This means that users don’t have to remember to submit opportunities for approval.
    • Submit for Approval is also available in Flow Builder as a core action
  • Users can view open approval requests by adding the Items to Approve component to their Home page.
  • Users can respond directly to approval requests directly from email or Chatter, as well.