Start tracking your progress
Trailhead Home
Trailhead Home

Use External Services in a Flow

Learning Objectives

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

  • Find your External Services-generated Apex actions in the Flow toolbox.
  • Create a simple flow with your External Services–generated Apex actions.

Apex Actions in Flow

If you completed the previous unit, you’ve registered an external service using the External Services Wizard and viewed the generated Apex actions in the wizard. To see the actions, let’s jump into Flow Builder.
  1. From Setup, enter Flow in the Quick Find box, then select Flows.
  2. Click New Flow, select Screen Flow, and click Create.
  3. From the toolbox, drag Action onto the canvas.
  4. To see the Apex actions imported by External Services based on the schema we used in the previous unit, change Filter By to Type, select External Services, and click in the search box.
The Flow Builder with External Services Apex actions visible.

For example, you can see the getAccount method that we looked at in the External Services wizard, along with addAccount, DeleteAccount, and updateAccount. These Apex actions are the methods pertaining to our fictional bank that we can use in a flow to find out information, add accounts records, and so forth. External services that you work with can have many more methods; it depends on the specific service that you use and how the schema is defined based on your use case.

We’re about to use these actions in a flow of our own. First let’s create a custom field on the User object.
  1. From Setup, select Object Manager, then select User.
  2. Click Fields & Relationships, then click New.
  3. Select Text and Next.
  4. For Field Label, use Account Type and for Length use 25. Leave the rest of the defaults, and click Next.
  5. Make sure that the field-level security is set to visible for profiles you use in your org and click Next, then Save.
You’ll find out why we need this field later.
Let’s create a user record for an employee, Maria Jones.
  1. From Setup, enter Users in the Quick Find box, then select Users.
  2. Click New User.
  3. For First Name, enter Maria.
  4. For Last Name, enter Jones.
  5. For User License, select Salesforce.
  6. For Profile, select Standard User.
  7. Since this is a test org, use your own email address.
  8. Enter a username and nickname to use and save.
Now let’s get started on our flow.

Create a Flow Using External Services-Generated Actions

Ready to get to it? Let’s create an account record in our fictional bank. The account record is for an employee who has signing authority on one of the organization’s accounts.

  1. From Setup, enter Flow in the Quick Find box.
  2. Click New Flow, select Screen Flow, and click Create.
  3. From the toolbox, drag the Screen element onto the canvas.
  4. In Label, type Account Information.
  5. From the list of Input screen components, drag two Text components to the screen canvas.
  6. Click the first Text component and under Label, type Name on Account.
  7. Click the second Text component and under Label, type Account Type and click Done.
  8. Click Save and set the flow’s properties.
    1. Flow Label: Employee Bank Record.
    2. Flow API Name: Employee_Bank_Record
  9. Click Save. If a warning appears, ignore it.
So far, we simply added a screen element to our flow. Now we add an element specific to our schema, so that the flow uses the addAccount method to create an account record at our fictional bank.
  1. From the toolbox, drag the Action element onto the canvas.
  2. Change Filter By to Type, select External Services, and click in the search box.
  3. Select addAccount.
  4. For Label, use Add Employee Record.
  5. Under Set Input Values, select to include accountName and accountType. For accountName, enter Name and select Name_on_Account. For accountType, enter Type and select Account_Type.
  6. Click Done.

    Edit addAccount Core Action screen

Now we need a record variable for the employee’s user record.

  1. From the Toolbox, select the Manager tab.
  2. Click New Resource and create a variable with these properties.
    1. Resource Type: Variable.
    2. API Name: accountTypeField
    3. Data Type: Record
    4. Object: User
    5. Availability Outside the Flow: Available for output
  3. Click Done.

Let’s map the account type from the output of the external service to the user record variable we just created.

  1. From the toolbox, drag the Assignment element onto the canvas.
  2. For Label, enter Assign Account Type.
  3. For Variable, click > next to the accountTypeField variable you created, and select Account_Type__c.
  4. For Operator, make sure Equals is selected.
  5. Click in the Value, search box, then click > next to the Outputs from Add_Employee Record, click > next to 201, and select z0type.
  6. Click Done.

    Edit Assignment screen

Almost there! Connect the Start element to your Account Information screen. Then, connect Account Information to the Add Employee Record element. Save your work.

You can use debug mode to check your flow. Click Debug, select Show details of what's executed and render flow in Lightning runtime, and click Run. For Name on Account, type Jones and for Account Type, enter Purchasing. The flow executes with our inputs.
Details after running the flow in debug mode.

Under Outputs, {!accountTypeField.Account_Type__c} = accountDetails_type_201 () reflects that as output, we assigned the action for creating an account, accountDetails_type_201, to the variable for account type that we created. We’ll use this output in our challenge to update a Salesforce record.

We could have received an error, too. For example, if we used Maria Jones for Name on Account, we would have received an error as defined in the schema, since a space is illegal in this field.


If we create a flow to use with an actual external banking service, you can imagine that we’d create records using unique identifiers and not names! But again, we’re keeping it simple here so that you can focus on External Services.

We can also check if the account was created by using the getAccount method. If you want to try that on your own, you can do that now. However, create another flow to do this. In the challenge, we build on the flow we just finished, so let’s not change it.

Summing It All Up

Remember that diagram from the first unit? Here it is again:
Graphic depiction of the External Services process.
We’ve now walked through all the steps. Notice that while we had to deal with a schema, a lot of the work we did was declarative. Nice, huh?
  1. An external services provider, such as a bank, shares its REST-based API schema specification: We got this information from our fictional bank.
  2. Based on the specification, a developer (or maybe even you) creates a schema definition that describes the API: While we didn’t create this schema ourselves, we reviewed the elements of a schema and the requirements for a good one. When you work with external services, you or your developer can define the schema you need for your use case.
  3. A Salesforce administrator declaratively creates a named credential to authenticate to the service’s endpoint using the URL provided by the external service provider: We defined our named credential,
  4. A Salesforce administrator declaratively registers the service and uses both the named credential and schema definition during the registration process: We just registered our first external service and looked at the generated Apex actions in the wizard.
  5. A Salesforce administrator declaratively creates a flow using the External Services–generated Apex actions: We just created a flow.
  6. Users run the flow: We used the debugger to make sure it runs correctly.
  7. Data is retrieved, created, updated, or deleted: We created an account record using the REST-based api of the service provider. But we aren’t done yet! In the challenge, we also update a Salesforce record using the same flow.