Lecture 20_Salesforce Automation and Lightning Flows: Comprehensive Notes
Salesforce Automation and Flows
Introduction to Automation
The lecture covers automation in Salesforce, transitioning from classic workflow rules to Lightning Flows.
Classic workflow rules involved actions like email alerts, field updates, task assignments, and outbound messages.
Process Builder was introduced as a more advanced automation tool with eleven actions.
Salesforce recommends using declarative (admin) methods over programmatic (code) when possible.
Salesforce Best Practices
Declarative vs. Programmatic: Salesforce recommends using declarative methods (admin, configuration) over programmatic methods (customization, coding).
Field Requirements: Avoid making fields required at the field level; use page layouts instead.
Synonyms:
Admin: declarative, configuration, point and click, drag and drop.
Development: customization, programs, coding.
Evolution of Automation Tools
Workflow Rules: The initial automation tool.
Process Builder: An evolution of workflow rules with more capabilities.
Lightning Flows: The latest automation tool, designed to solve problems not addressed by previous tools.
Lightning Flows
Lightning Flows are a type of automation where an event triggers a subsequent action.
Flows are accessed in Salesforce Setup under Process Automation > Flows.
The Flows page displays existing flows, including those from managed packages provided by Salesforce.
Creating a new flow involves choosing between building from scratch or using a template.
Types of Flows
Screen Flow:
A manual process that guides users through a business process.
Launched from Lightning pages or Experience Cloud sites.
Can capture user input through screens.
Record Trigger Flow:
Launches when a record is created, updated, or deleted.
Operates in the background, similar to Process Builder.
Schedule Trigger Flow:
A record trigger flow that runs on a schedule.
Similar to time-dependent workflows.
Platform Event Flow:
Triggered by an event in an external system.
Used for integrations, such as with an ERP system.
Example: Updating Salesforce when a product is out of stock in Tally.
Auto Launched Flow:
Used primarily by developers for complex logic.
Can be called from other flows or Apex code.
Orchestration:
Launches when a record is created or updated.
Allows creating multi-step processes involving multiple users or teams.
Building a Screen Flow
Canvas: The main area for building the flow.
Toolbox: Located on the left-hand side, contains elements, manager etc.
Buttons: Run, Debug, Activate, Save As, Save, and Auto Layout.
Elements:
Interaction: Screens for user input.
Logic: Decisions, loops, and assignments.
Data: Actions to create, update, or delete records.
Switch from Auto Layout to Freeform to manually connect elements.
Screen Flow Example: Displaying "Hello, World!"
Create a new Screen Flow.
Drag a Screen element onto the canvas.
Add a Display Text component to the screen.
Enter the text "Hello, World!" in the Display Text component.
Optionally, format the text (e.g., make it bold).
Connect the Start element to the Screen element.
Save the flow with a descriptive name.
Debug the flow to test it.
Screen Flow Example: Contact Search
Scenario: Create a screen flow that allows users to search for a contact by first name and last name.
Add two Text Field components to the screen for first name and last name input.
Add a Get Records element to retrieve the contact record based on the entered first name and last name.
Configure the Get Records element to filter contacts where:
FirstName equals the value entered in the first name text field.
LastName equals the value entered in the last name text field.
Get Records Element
Used to retrieve records from the Salesforce database.
Specify the object to retrieve records from (e.g., Contact).
Define filter conditions to identify the desired record.
Map the retrieved record's fields to variables for use in the flow.
Screen Flow Example: Updating Contact Email
*Scenario
1) Global search using first and last name.
2) Contact's current email ID is shown.
3) Provide an option to enter and update with a new email ID.
Adding a Screen to Display Current Email
*Add a Display Text component to the screen to show the current email address of the searched contact.
*Use a variable to dynamically display the email address from the Get Records element.
*Format variables as .
Adding a Screen to Enter New Email
*Add an Email Field component to the screen to allow users to enter a new email address.
Update Records Element
*Use an Update Records element to update the contact record with the new email address.
*Specify conditions to identify the record to update (e.g., Contact ID equals the ID from the Get Records element).
*Set the Email field to the value entered in the new email address field.
Debugging the Flow
*Use the Debug button to test the flow and ensure it's working correctly.
*Verify that the contact record is updated with the new email address.
Assignment: Phone Number Update
*Modify the existing flow to allow users to update the contact's phone number instead of the email address.
*Object: Contact
*Action: Show the contact's existing phone number and provide an option to update it with a new phone number.
Assignment: Create Record
*Use the create record element. Single Screen to create a new record given the following object.
*Create a new Lead and new Contact - mandatory field = Last Name, Company, Lead Status.
*Follow best practices, complete the test and note results, and ask where appropriate.
Create Record Element
Used to create new records in the Salesforce database.
Specify the object to create a record for (e.g., Account).
Set the field values for the new record using either:
Use all field values from a record or record collection.
Use separate resources, and literal values.
Review and Best Practices
*Review the assignments done, and repeat building elements as needed and debug. Do not simply copy.
*The assignments are to not be copy/pasted, but built from the ground up. Note iterations where appropriate so the debug flows can be referenced later.
*Delete the final assignment for total immersion, knowing the base best practices used. The goal is to work logically, step by step. If these steps are followed, Screen Flows will work correctly.
*Please reach out to the instructor shall there be any questions.