1

Can anyone share with me documentation or examples on how to test an apex class that is dependent on a process builder job?

My problem is the process builder job comes over from Sandbox as inactive. The process builder job is calling the apex class.

Is there some way to activate the process builder in the test class?

1
  • 2
    As the answer below states, write your tests like the PB does not exist. You are testing the code not the PB functionality. In future if PB is changed you would not want your tests to fail just because the PB was modified. Test should ensure that IF your code is executed that it will do what you expect it to – Eric Jan 20 '17 at 15:02
13

you can write a test class independent of process builder active/ inactive by calling methods in your main class (dependent on process builder) directly from test class. Another alternative is to use ant for deploying process builder with active status instead of changeset deployment. Link here.

3

To add to the existing answer, this situation isn't really any different than testing a trigger. You have three basic aspects you need to verify:

  • Action - What happens?
  • Filter - Which records are acted on?
  • Trigger - Are the above bound to database events?

When you use Process Builder to invoke Apex, you only have to Unit Test the Action. The other two aspects are configuration and should be tested functionally, not via automated unit testing.

The code does not care if it is bound to any database events, nor which records to act on. That's not its job, and it's not what you should test. The code just cares about what it should be doing with the supplied input, and that is what you should test. It's just like testing any other Service layer method.

static testMethod void testMyInvocableMethod()
{
    // set up data 

    Test.startTest();
        //directly invoke method
    Test.stopTest();

    // assert on behavior
}

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.