Skip to main content
Scheduled Maintenance: Trailhead, myTrailhead, and Trailblazer Community will be offline January 17, 16:00–20:00 UTC. Thanks for bearing with us as we update your experience!

Get Hands-On by Running Apex and Flow Tests Together

Learning Objectives

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

  • Use the Test Discovery API to get a unified view of Apex and automated flow tests.
  • Use the Test Runner API to execute Apex and flow tests together in a single run.
  • Run and view Apex and automated flow tests declaratively in Setup.

Unify Your Test Execution

Keeping track of separate Apex and flow tests can be a hassle — now you can see them all in one place. The new Test Discovery API gives you a single view of every Apex and automated flow test in your org. Then, use the updated Test Runner API to execute both types of tests in the same run.

Both APIs are Tooling API REST resources, so you can integrate them into your developer workflow. Prefer to work declaratively? You can now run Apex and flow tests right from Setup.

Get Hands on Running Apex and Flow Tests Together

Get a unified view of your existing Apex and automated flow tests with the new Test Discovery API. Use the updated Test Runner API to execute Apex and flow tests in the same test run. Both APIs are Tooling API REST resources. You can also run and inspect both Apex and automated flow tests declaratively in Setup.

Install the Managed Package

You’ll want to follow along with the steps in this module to pass the challenge. In order to do so, you need to install a package in your Trailhead Playground. Follow the instructions here to launch a playground and install the package. You also use this package and playground when it’s time to complete the hands-on challenge.

Launch your Trailhead Playground by scrolling to the bottom of this page and clicking Launch.

If you see a tab in your org labeled Install a Package, great! Follow these steps:

  • Click the Install a Package tab.
  • Paste 04tNS000000EQYv into the field.
  • Click Install.
  • Select Install for Admins Only, then click Install.

If you don't see the Install a Package tab, open the App Launcher, find Playground Starter, and follow the steps. If you don’t see the Playground Starter app, copy and check out Install a Package or App to Complete a Trailhead Challenge on Salesforce Help.

When the package is finished installing, you see a confirmation page and get an email to the address associated with your playground. Click Done and and navigate to Setup.

Create a Record-Triggered Flow

Let’s get started by selecting an object and defining the entry conditions.

  1. From Setup, search for and select Flows.
  2. Click New Flow.
  3. Under Frequently Used, select Record-Triggered Flow. If Record Triggered Flows isn’t visible, search in the top right search bar.
  4. For Object, select Account.
  5. For Trigger the Flow When, select A record is created or updated.
  6. For Set Entry Conditions, under Condition Requirements, leave None selected.
  7. Define the condition:
    • Optimize Flow: Actions and Related Records
    • Add Asynchronous Path: Toggle Off

Add an Element

Add an element to trigger the record.

  1. Click the Add Element icon, and select Update Triggering Record.
  2. Update the following:
    • Label: Update Description
    • API Name: Update_Description
    • How to find Records to Update and Set Their Values: Use the account record that triggered the flow.
    • Set Filter Conditions: None - Always Update Record

Set Field Values for the Account Record

Next, add values to the Field column.

  1. In the Field column, select Account Description.
  2. In the Value column, click New Resource. A popup dialog box opens.
      • Select Text Template as Resource Type
      • API Name: Default_Description
      • In the Body section, select View as Plain Text.
      • Paste the following in the text editor: This is a default description.
      • Click Done.
  3. Verify Default_Description is in the Value column.
  4. Click Save, and set the following details:
    • Flow Label: Account Update
    • Flow API Name: This will autopopulate with Account_Update
    • Leave Description blank.
  5. Click Save.
  6. Click Activate.

Setup Test for Flow

Before testing, set up the testing parameters.

  1. Click View Tests.
  2. Click Create.
  3. In Set Test Details, Trigger, and Path, enter the following information:
    • Label: Test Account Update Description
    • API Name: This will autopopulate with Account_Update_Test_Account_Update_Description
    • Leave Description blank.
    • Run the Test When a Record is: Created
  4. Click the Set Initial Triggering Record tab.
    • In the Account Name field (you will need to scroll down to find this field), enter Account with Flow.
  5. Click the Set Assertions tab.
    • In Assertion 1:
      • Resources: Triggering Account -> Account Description
      • Operator: Is Null
      • Value: False
  6. Click Save.

Run and Verify the Test

You’re now ready to run and verify the tests.

  1. Navigate to Setup in the top right corner of the page, and select Developer Console.
  2. Click Debug, and select Open Execute Anonymous Window.
  3. Paste the following command into the window: RunTestsUsingToolingAPI.runAsynchronousTestsWithToolingAPI();
  4. Click Execute.
  5. Navigate to Setup.
  6. In the Quick Find box, search for and select Application Test Execution.
  7. Select the Apex and flow tests you want to run, then click Run.
  8. To check the test run results, click the View Test History link.
Note

The Application Test Execution and Application Test History pages replace the old Apex Test Execution and Apex Test History pages.

Nice job! You now know how to run Apex and Flow tests together.

If you’ve followed all the above steps, you’re now ready to click Check Challenge to Earn 500 Points.

Teilen Sie Ihr Trailhead-Feedback über die Salesforce-Hilfe.

Wir würden uns sehr freuen, von Ihren Erfahrungen mit Trailhead zu hören: Sie können jetzt jederzeit über die Salesforce-Hilfe auf das neue Feedback-Formular zugreifen.

Weitere Infos Weiter zu "Feedback teilen"