2

I'm trying to write a Test class to test a Scheduled flow. However I'm not sure how to call this flow. :/

I've tried the following on the my testMethod

@isTest
    static void testMethod1(){
    Test.startTest();
    Flow.Interview myFlow = flow.Interview.createInterview('Flow Name', New Map<String,string>());
    myFlow.start();
    Test.stopTest();
}

However, I get the following error:

FATAL_ERROR System.FlowException: The flow failed to start because the provided values were not valid: 
You can't launch a schedule-triggered flow by clicking Run in Flow Builder. To test this flow, 
click Debug and then Run. To launch this flow, activate the flow and wait until the scheduled time.

Has anyone found a way of testing a scheduled flow?

Thanks

2
  • Why do you need to test this flow? I'm pretty sure you can't, but I'd be interested in your use case.
    – sfdcfox
    Jan 21, 2021 at 20:40
  • Would be for regression testing basically, to pick if any org chance could break this flow. Since we can test an automated flow, or a scheduled apex class, I was wondering if we could test a scheduled flow as well.
    – PanicNot
    Jan 21, 2021 at 21:55

1 Answer 1

0

You can recreate your flow as an auto-launched one and use the scheduled flow only for the scheduling of the flow.

This way you can test the logic in the Auto-Launched flow by mocking the scheduled flow conditions and start the flow with code.

You can also create another auto-launched flow that is triggered by the schedule to create a logfile externally or as a record to see if the scheduling is working (Heartbeat style)

To my current knowledge there is no way to test the scheduling itself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .