7

We have an org where we are using Process Builder to create cases 1 hour after a record have been created with missing data. We are using a scheduled action (Call apex) to do so. We are using the "Call Apex" instead of "Create Record" as the later does not have the functionality to e.g. add fill in Record Types by Name. The functionality seems to be working fine, but we want to include all of our business logic in apex test classes, including this one. When writing the unit test, what I had problem with is to simulate that one hour have passed since the creation of the record. The scheduled process builder action is not running after the the record have been created. First I tought that the scheduled process builder actions are fired after the Test.stopTest() method similarly to scheduled apex but this is not the case. Is there any way to test these scheduled action in apex? Thanks!

2
  • 3
    Are you using an Apex Plug-in that you've written to do this? If so, the only thing you could do would be to unit test the plug-in by itself. Otherwise, one would normally test this type of thing just as they would with regular workflow, by looking to see if it's been scheduled, but as I understand process builder, it rechecks the conditions before firing time based workflow which is probably why Test.stopTest doesn't work for unit testing. – crmprogdev Jan 8 '16 at 15:13
  • 1
    If you want to unit test functionality, it probably belongs in Apex. – Adrian Larson Jan 10 '16 at 23:59
0

The only way I found is to assert the Flow call, after it satisfies the Condition Criteria. See the code below:

List<FlowInterview> flowInterviews = [SELECT Id FROM FlowInterview];
System.assertEquals(1, flowInterviews.size());

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.