Skip to main content

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.
Note

This badge is one stop along the way to Flow Builder proficiency. From start to finish, the Build Flows with Flow Builder trail guides you through learning all about Flow Builder. Follow this recommended sequence of badges to build strong process automation skills and become a Flow Builder expert.

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.

Note

This badge uses record-triggered flows, which have additional configuration and features. You might not have learned about record-triggered flows yet so we step you through the examples. To learn more about configuring record-triggered flows, check out the Record-Triggered Flows badge.

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.

  1. Create a record-triggered flow:
    1. Object: Account
    2. Trigger the Flow When: A record is created
    3. Condition Requirements: All Conditions Are Met (AND)
    4. Field: Type
    5. Operator: Equals
    6. Value: Prospect
    7. Optimize the Flow for: Actions and Related Records
  2. On the flow canvas, on the path after the Start element, hover over Add Element  and click Add Element. Select Create Records.
  3. 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.
  4. For Description, enter Create a task named Follow-Up Discovery Call, assigned to the account’s owner.
  5. For How Many Records to Create, select One.
    (Yes, you can create more than one record if you select Multiple, but that comes later in another badge.)
  6. For How to Set the Record Fields, select Use separate resources, and literal values.
    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.
  7. For Object, select Task.
    The New Create Records panel corresponding to steps 3-7
  8. Now, under Set Field Values, you set the value for each field you want in the new task record:

    Field Value
    OwnerId $Record > OwnerId
    (Scroll down and select the OwnerId field, not the Owner object. If you selected the correct OwnerId, the Value field shows An icon with an uppercase A and a lowercase a. after you select another field.)
    Priority Normal
    Status Not Started
    Subject Follow-Up Discovery Call
    (Enter this text directly instead of choosing a picklist value.)
    WhatId $Record > Id
    Note: $Record is a special variable that’s frequently used in record-triggered flows. It contains the fields in the record that triggered the flow. For example, $Record > OwnerId indicates the Owner of the triggering record. To use $Record in a flow, select it from the Global Variables section when selecting a resource.
  9. 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 element description icon next to it. Hover over the icon to display the element’s description.

The Create Follow-Up element’s description: Create a task… assigned to the account’s owner.

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.

  1. Create a record-triggered flow:
    1. Object: Contact
    2. Trigger the Flow When: A record is created
    3. Condition Requirements: All Conditions Are Met (AND)
    4. Field: Phone
    5. Operator: Is Null
    6. Value: $GlobalConstant.True
    7. Optimize the Flow for: Fast Field Updates
  2. On the flow canvas, on the path after the Start element, hover over Add Element  and click Add Element. Select Update Records.
  3. For Label, enter Set Contact Phone.
  4. Under How to Find Records to Update and Set Their Values, Use the contact record that triggered the flow is the only available option.

    The New Update Records panel corresponding to steps 4 and 5.
  5. Under Set field values for the contact record:
    1. For Field, select Phone.
    2. For Value, select $Record > Account > Phone.
  6. 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.

Note

Deleting Salesforce records should never be done lightly. If you have to delete records, be sure you test your flow thoroughly in a sandbox before activating it for your users. You don’t want your flow to start automatically deleting the wrong records.

Also, keep in mind that records usually come into existence for a reason, even if that reason is just evidence that something went wrong. As a general rule, avoid deleting records unless it should never have existed in the first place, and you don’t need a record of its existence for future records or research.

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.

The New Delete Records window corresponding to the preceding description.

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

Lernen Sie weiter kostenlos!
Registrieren Sie sich für einen Account, um fortzufahren.
Was ist für Sie drin?
  • Holen Sie sich personalisierte Empfehlungen für Ihre Karriereplanung
  • Erproben Sie Ihre Fähigkeiten mithilfe praktischer Aufgaben und Quizze
  • Verfolgen Sie Ihre Fortschritte nach und teilen Sie sie mit Arbeitgebern
  • Nutzen Sie Mentoren und Karrierechancen