進行状況の追跡を始めよう
Trailhead のホーム
Trailhead のホーム

Add Actions to Your Flow

Learning Objectives

After completing this unit, you’ll be able to:

  • List the actions available in Flow Builder.
  • Understand when to use a record variable in a data element.
  • Configure a Post to Chatter core action.

Work with Salesforce Data from a Flow

The real power of a flow is that it can automatically do things on behalf of the user, including making updates to your data, sending emails, sending information to an external system, and (thanks to integration with Apex and local actions) pretty much anything else you can imagine.

In a flow, you can get values from records, connect to external systems, create records, update records, delete records—the whole shebang!

Note

Note

The options don’t stop with Salesforce objects. With data elements, you can also:

  • Publish platform event messages (available only in Create Records elements)
  • Work with external object records

Get Records

In a Get Records element, you identify which object to look up, how to filter the object’s records, and how to sort the filtered records. Then you specify how many records to store and where to store those records’ values.

If you choose to store all the records that meet the filters, you must store the records’ values in a record collection variable. If you choose to store only the first record, you may store that record’s values in a record variable or in separate variables.

Let’s look at the Find a Match element in your New Contact flow.

A Get Records element, which grabs contact records, where the first name and last name match what the user entered in the Contact Info screen. Then it stores the ID of the first returned contact in the {!existingId} variable.

It looks for at least one contact (1) that matches the first and last name the user entered on the screen (2). Back in the Name screen component, you stored the First Name value in {!contact.FirstName} and the Last Name value in {!contact.LastName}. If the flow finds a match, it stores that contact’s ID in the {!existingId} variable (3). Otherwise, it sets the variable to null (4).

(Remember, the {!existingId} variable is used in the Update or Create? decision to determine whether there’s a contact to update.)

Update Records Elements

In an Update Records element, you identify which records to update and how to update those records.

  • If you choose to use a record variable or record collection variable, the flow uses the IDs in that variable to identify the records to update, then updates the records by using the other field values in the variable.
  • Otherwise, you can manually set filter conditions to identify the records to update. With this option, you also manually identify the field values to change.

Here’s a comparison of what the Update Contact element in the New Contact flow looks like for each option.

Record variable option An Update Records element that uses the values from the {!contact} record variable
Manual option An Update Records element that manually maps the field values by using resources from the flow

The Update Contact element uses a record variable to update the matching contact record, because the flow populates the {!contact} record variable with the right values throughout the flow.

  • FirstName and Last Name are populated with in the Contact Info screen
  • Id is populated in the Set Contact ID assignment

Create Records Elements

To create multiple records, you must use the values from a record collection variable. Earlier in the flow, populate the record collection variable with the new records’ field values. For each record that’s created, the flow stores the ID of the created record in the ID fields of the record collection variable.

To create one record, you have two options for setting the record’s values.

  • If you’ve populated a record variable with the field values for the new record, choose to set the record fields by using all the values from a record variable. Then select the record variable or record collection variable to use. When the record is created, the flow stores the ID of the created record in the record variable’s ID field.
  • To manually map values from various resources in the flow, choose to set the record fields by using separate variables, resources, and literal values. Optionally, store the ID of the created record in a Text variable.

Here’s a comparison of what the Create Contact element in the New Contact flow looks like for each option.

Record variable option A Create Records element that uses the values from the {!contact} record variable]
Manual option A Create Records element that manually maps the field values by using resources from the flow

The Create Contact element uses a record variable to update the matching contact record, because the flow populates the {!contact} record variable’s FirstName and LastName fields in the “Contact Info” screen.

Perform Other Actions from a Flow

Now you’re all set if you need to manipulate Salesforce data from a flow. For anything else, you need the action elements in Flow Builder.

Action elements in the Flow Builder toolbox

The Action Element

Each action element has the same layout. To configure any action element, you first select the action type (which corresponds to the list under the Actions category in the Elements tab in the Toolbox) and then select the specific action to use.

The Core Action element

Each action requests some values so it knows what to do. These are inputs. For example, Post to Chatter requests five inputs, which you use to identify what to post (See the Message field below) and where to post it.

The Set Input Values tab in the Post to Chatter core action

Some actions respond with information, usually related to the results of the action. These are outputs. For example, Post to Chatter offers the ID of the feed item it created. If you want to use that ID later in the flow, such as to display a link to the created Chatter post, store the value in a flow variable.

The Store Output Values tab in the Post to Chatter core action

Action Types

Without creating or configuring anything else in Salesforce, you can use these actions, available from the Core Action element.

  • Post to Chatter.
  • Send Email.
  • Submit For Approval.
  • Activate or Deactivate a Permission Set.
  • Global or object-specific actions provided by Salesforce.

The next layer of actions includes those you create with clicks.

  • Your org’s workflow email alert actions are available in the Email Alert element.
  • Other flows in your org are available in the Subflow element.
  • Custom global or object-specific actions are available in the Core Action element.

The last layer of actions includes those that require code. Of course, you can install custom actions from AppExchange or a third-party library.

  • To do something in the Salesforce database, build or install an Apex action. They’re available in the Apex Action or Apex Action (Legacy) elements.
  • To do something in the browser, build or install a local action. They’re available in the Core Action element.

Update the Flow

According to the business requirements from the Flow Basics module, it’s not enough to summarize what the flow did in a confirmation screen. Let’s quickly recap the requirements.

Requirement Element Type to Use
Collect information from user: first name, last name, and account for contact, as well as what to do if a matching contact exists. Screen
Find a matching contact record. Action
Check if a matching record was found. Logic
If no match exists, create the contact. Action
If a match exists, update that contact. Action
For both branches, confirm what the flow did in Chatter. Action
For both branches, confirm that the flow is done. Screen

So far, the flow meets every requirement except the last action: Confirm what the flow did in Chatter.

Add a Post to Chatter Action

  1. Drag a Core Action element onto the canvas.
  2. For Core Action, enter Cha and select Post to Chatter.
  3. Give the action a label: Post to Contact's Feed.
  4. Set the action’s inputs. The input values identify the message to post and which Chatter feed to post it to. For this use case, you only set the required inputs.
    1. For Message, click New Resource and select Text Template.

      Text templates are useful resources for adding merge fields or HTML formatting to some text.

    2. Name the text template chatterMessage.
    3. For Text Template:
      1. Enter The contact was .
      2. In the resource picker, enter created and select the formula you created earlier: created_or_updated.
      3. Add a period to finish that sentence.

      Here’s the final text template: The contact was {!created_or_updated}.

    4. Click Done.
    5. For Message, enter message and select the text template you just created.
    6. For Target Name or ID, enter {!contact.Id}, and select the Id field.
    7. Click Done.

You’ve now successfully configured an action to post a message, using a text template, to the Chatter feed of the contact record that the flow created or updated.

Connect the Elements

The last step is connecting the action to the rest of the flow so the Chatter post is created when the flow runs. Let’s place the action before the confirmation screen, so the confirmation is the last step in the flow.

  1. Connect the Create Contact and Update Contact elements to the Post to Chatter core action.
  2. Connect the Post to Chatter core action to the Confirm screen.
  3. Save the flow, and ignore the warning.
    The “New Contact” flow, with the new Post to Chatter core action and its connectors highlighted.

Well done! The New Contact flow now meets all the requirements covered in the Flow Basics module. Now that the flow is built to the business requirements, it’s time for the next step: learn how to test a flow, activate it, and distribute it to users in the next module, Flow Testing and Distribution.

Resources

retargeting