Work with Salesforce Records in Flows
Learning Objectives
After completing this unit, you’ll be able to:
- Understand how flows interact with Salesforce records.
- Build a flow that creates a Salesforce record.
- Build a flow that updates a Salesforce record.
Before You Start
This unit expands on what you learned in previous badges. If you aren’t familiar with variables or need a refresher, see the Learn About Flow Variables unit in the Flow Builder Basics badge.
In Salesforce, flows are flowcharts that actually do stuff. So let’s talk about the stuff that flows can do.
The Power of Flow Builder
The true power of a flow is that it can automatically do things on behalf of the user, such as: update data, send emails, submit records for approval, and interact with an external system. Flows have nearly unlimited flow-tential!
You learned about variables in the Flow Builder Basics module, but it’s important to note that making a change to a variable does not affect your Salesforce records. To push variable changes to records, or to interact with Salesforce data in any way, you use data elements. These elements can get values from records, create records, update records, delete records—the whole enchilada!
Before we get into the details, watch this video about data elements.
Create a Single Record from Scratch
Flows can create a record for any type of object in Salesforce: standard objects, custom objects, even background objects you may never have seen before. The key thing to keep in mind is that if you see it in Object Manager, you can create a record for it. Accounts, contacts, leads, tasks, opportunity products, service contracts, custom objects… they’re all fair game. You can even create records for some API-only objects, but those objects tend to have greater requirements or downstream effects, so be careful.
When creating records, you can create one record or many records at once, depending on how you configure the Create Records element. Creating multiple records requires a specific type of variable (called a record collection variable), so we’ll talk about that when we learn about collection variables. For now, let’s focus on creating a single record.
Flo Smith is a Salesforce admin and business analyst for Pyroclastic, Inc. In this module, you’re a Salesforce admin on Flo’s team, helping her automate some of Pyroclastic’s business processes.
Pyroclastic’s sales managers want to remind the owners of new account records to reach out to their new accounts. Flo asks you to build a flow that creates follow-up tasks on new accounts. You’ll do that by using the Create Records element in your new flow.
Ready to Get Hands-on with Flow Builder?
Launch your Trailhead Playground now to follow along and try out the steps in this module. To open your Trailhead Playground, scroll down to the hands-on challenge and click Launch. You also use the playground when it's time to complete the hands-on challenges.
- Create a record-triggered flow:
- Object: Account
- Trigger the Flow When: A record is created
- Condition Requirements: All Conditions Are Met (AND)
- Field: Type
- Operator: Equals
- Value: Prospect
- Optimize the Flow for: Actions and Related Records
- On the flow canvas, on the path after the Start element, click . Select Create Records.
- For Label, enter
Create Follow-Up
.
The label becomes the element’s identifier on the canvas and everywhere else it’s referenced in the flow. So make sure you give it a descriptive name.
- For Description, enter
Create a task named Follow-Up Discovery Call, assigned to the account’s owner
.
- For How to set record field values, select Manually.
This option lets you declare each field’s value individually, which makes it a great option when you want to create a record with data from multiple sources.
- For Object, select Task.
- Now, under Set Field Values, you set the value for each field you want in the new task record:
- Field: Assigned To ID, Value: Triggering Account > Owner ID (Scroll down and select the Owner ID field that doesn’t have a > at the end of the line.)
- Field: Priority, Value: Normal
- Field: Status, Value: Not Started
- Field: Subject, Value:
Follow-Up Discovery Call
(Enter this text directly instead of choosing a picklist value.)
- Field: Related To ID, Value: Triggering Account > Account ID
- Field: Assigned To ID, Value: Triggering Account > Owner ID (Scroll down and select the Owner ID field that doesn’t have a > at the end of the line.)
- Save the flow. For Flow Label, enter
Create Follow-Up on New Prospect
.
You can also use these methods in many other elements throughout Flow Builder.
Describe Your Flows
In the Create Records element you just added, you entered text in the Description field. When an element has a description, that element displays the icon next to it. Hover over the icon to display the element’s description.
It’s best practice to enter a description whenever possible. Descriptions document your automation. This documentation is accessible to any admin who opens the flow, eliminating guesswork and making it easier to troubleshoot problems. It’s a small amount of work that can save a lot of time and frustration down the road.
To save you the effort of numerous copy-pastes, we don’t include descriptions in all Trailhead exercises and challenges, but they’re definitely a best practice in real life.
Update a Single Record
If a record exists in Salesforce, flows can edit it. You just have to tell the flow which record to edit, and what changes to make.
Flo Smith has another request from Sales. This one is from the division that handles upsells. They run reports to create call lists, but sometimes the contacts don’t have phone numbers. Not having to search for a number would save the sales agents a lot of time. Flo asks you to create a flow that checks whether a contact has a phone number and if it doesn’t, copies the related account’s phone number to the contact.
To update a record in a flow, use the Update Records element.
- Create a record-triggered flow:
- Object: Contact
- Trigger the Flow When: A record is created
- Condition Requirements: All Conditions Are Met (AND)
- Field: Phone
- Operator: Is Null
- Value: $GlobalConstant.True
- Optimize the Flow for: Fast Field Updates
- On the flow canvas, on the path after the Start element, click . Select Update Records.
- For Label, enter
Set Contact Phone
.
- Under How to Find Records to Update and Set Their Values, Use the contact record that triggered the flow is the only available option.
- Under Set field values for the contact record:
- For Field, select Phone.
- For Value, select $Record > Account > Phone.
- Save the flow. For Flow Label, enter
Copy Account Phone to New Contact
.
Delete Records
Of course, not every Salesforce record lives forever. Sometimes a record just needs to be swept up by the flownado and carried off to Oz. (Or at least, to the Recycle Bin.) When you want to use a flow to delete a record, use the Delete Records element.
The Delete Records element is similar to the Create Records and Update Records elements. In a Delete Records element, you set the conditions (3), object (4), and filters (5). Here’s an example.
But wait, there’s more! There’s another element that interacts with records. In the next unit, let’s take a look at how it and the other elements use variables.
Resources