2

I thought it would be a good idea to write some Apex testmethod automation to verify the scheduled paths on a record-triggered flow. But as far as I can tell, you can't do this (as of V51)

Am I right?

Flow

Updates Foo__c.ScheduledPathUpdate__c with current datetime when the path executes. It works fine in the UX.

enter image description here

Testmethod

static void testFlowInterview() {
    Test.startTest();
    insert new Foo__c(Name= 'RunFlowTest');
    Test.stoptest();
    System.debug(LoggingLevel.INFO,[select id, name, ScheduledPathUpdate__c from Foo__c]);

Debug log from testmethod

CODE_UNIT_STARTED|[EXTERNAL]|01p6300000GUbqz|FooAutomationTest.testFlowInterview()
DML_BEGIN|[10]|Op:Insert|Type:Foo__c|Rows:1
CODE_UNIT_STARTED|[EXTERNAL]|Flow:01I63000001xE61
CODE_UNIT_FINISHED|Flow:01I63000001xE61
CODE_UNIT_STARTED|[EXTERNAL]|Flow:01I63000001xE61
UNKNOWN|X1_HR|RunFlowTest|a1e63000000z78t|1|Hours|Thu Jun 10 21:33:11 GMT 2021
CODE_UNIT_FINISHED|Flow:01I63000001xE61
DML_END|[10]
SOQL_EXECUTE_BEGIN|[14]|Aggregations:0|SELECT id, name, ScheduledPathUpdate__c FROM Foo__c
SOQL_EXECUTE_END|[14]|Rows:1
USER_DEBUG|[14]|INFO|(Foo__c:{Id=a1e63000000z78tAAA, Name=RunFlowTest})
CODE_UNIT_FINISHED|FooAutomationTest.testFlowInterview()

You can see that the Flow entry conditions were evaluated as it clearly considers the +1 hour scheduled path. But no DML to update Foo__c occurs after Test.stopTest();

I'd be happy enough to verify that the scheduled paths were in fact scheduled but ...

  • there are no entries in FlowInterview before or after Test.stoptest();
  • Using the UX, you can see entries in Setup | Time-Based Workflow but this is derived from AFAIK an unqueryable SObject WorkflowTimeQueue
2
  • I think this answer provides background for why this doesn't work (since, you noted it's using the same table as time-based workflow actions which have had this limitation as well). It seems there was this idea that was sadly closed for low activity Jun 10, 2021 at 23:18
  • @KrisGoncalves - thanks for the link. Feel free to provide that as an answer.
    – cropredy
    Jun 11, 2021 at 19:19

1 Answer 1

1

This answer explains why certain declarative features are not run when running an apex test

Apex tests are for testing Apex. They are not designed to test for declarative features.

As you noted, the scheduled path in flow is utilizing the time-based workflow queue. The time-based workflow queue is not queryable via Apex or the API and leaves you with no real option to try and test this. You can upvote this idea that asked for the ability to test this type of scenario, but was closed with low activity.


In Summer '22, there's a beta for No-Code Flow Testing.

Before you activate a record-triggered flow, you can now test it to quickly verify its expected results and identify flow run-time failures. In Flow Builder, you create, save, and run flow tests.

However, the limitations do appear to exclude scheduled paths:

Flow tests are available only for record-triggered flows. Flow tests support only flow paths that run immediately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.