Test Process Scheduled Actions and Flow Resume Events with Apex

To help you provide more test coverage for behind-the-scenes automations, the stopTest Apex method executes processes’ pending scheduled actions and resumes flows that are waiting for a time-based resume event. Previously, Apex tests could start processes and autolaunched flows, but they couldn’t validate scheduled actions or whether a flow resumes.

Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

How: The stopTest method marks the point in your test code when your test ends. When stopTest is executed, all asynchronous processes are run synchronously.

For Apex tests that trigger record-change processes (built in Process Builder), the stopTest method executes scheduled actions for any date, even if the criteria group includes multiple schedules. For Apex tests that trigger event processes (built in Process Builder), publish the event, and use the Test.getEventBus().deliver() method to start the process. Use the stopTest method to execute associated scheduled actions.

For Apex tests that trigger autolaunched flows with Pause elements, the stopTest method resumes the flow and executes the remaining elements. For each Pause element that’s waiting on a time-based resume event, the flow resumes and executes all elements along the path.

Related Updates for Developers

Apex
Changed method in System.Test: stopTest()