You need to sign in to do that
Don't have an account?
Brian Hayes 12
How Do You Test a Flow with a Pause Element with an Apex Test Class?
I have a Apex test class to test a Salesforce flow. When I added zero wait (resume as-soon-as-possible) pause elements, the test no longer passed. I added the pause elements to deal with the transaction limits being encountered during bulkification.
What's a good solution to check for the flow being completed before executing the Test.stopTest() and performing assertions?
From what I've seen, there's no method on the Flow.Interview class for checking the flow completion status or for getting the flow instance id (start() returns void). I also see that there's a FlowInterview object that can be queried using SOQL; but, I worry about being able to idenify the unique flow instance if there are multiple instances of the flow with the same name.
Note, I did create a work around that I'm not satisfied with. I added a NoPause boolean input to the flow and then put a decision elment before each pause where the decision element checks the value of NoPause. In this way, the Apex test can provide the NoPause input set to true and the test passes. Unfortunately, this does not execute the typical path through the flow.
Thanks in advance!
What's a good solution to check for the flow being completed before executing the Test.stopTest() and performing assertions?
From what I've seen, there's no method on the Flow.Interview class for checking the flow completion status or for getting the flow instance id (start() returns void). I also see that there's a FlowInterview object that can be queried using SOQL; but, I worry about being able to idenify the unique flow instance if there are multiple instances of the flow with the same name.
Note, I did create a work around that I'm not satisfied with. I added a NoPause boolean input to the flow and then put a decision elment before each pause where the decision element checks the value of NoPause. In this way, the Apex test can provide the NoPause input set to true and the test passes. Unfortunately, this does not execute the typical path through the flow.
Thanks in advance!
Please note that the only Auto launched flows can be given testable classes at this time, and flows with triggers cannot be tested. This would mean that actions like Scheduled Actions, Pause Actions etc (actions which re-triggers another Action post some interval) can't be covered currently.
For a similar discussion around this topic, I recommend reviewing the following posts
https://salesforce.stackexchange.com/questions/296173/how-to-write-an-apex-test-for-a-process-builders-scheduled-actions
https://salesforce.stackexchange.com/questions/319507/test-class-apex-controller-for-lwc-bundle-that-displays-flow-pause-component
Let me know if this helps
Thanks,
Anudeep
Thank you for your response. The flow that I am testing is an autolaunched flow with Pause elements.
I did work with Nick at Premier Support; his research and collegues confirmed what you wrote: It's currently not possible to resume a paused flow from an Apex test class. (For those of you who read the second StackExchange post reference by Anudeep, note that it applies to Aura enabled Apex components).
I've submitted this idea to the IdeaExchange:
https://trailblazer.salesforce.com/ideaView?id=0874V000000chnBQAQ
Thanks,
Brian