8

I'm working on a project that entails refactor of a lot of complex workflow rules.

I was wondering if anyone here writes unit test to test their workflow rules? Seems like it would be a good idea to write a set of unit test before we begin refactoring.

Are there any best practices associated with doing this?

Some of the workflows are using outbound messaging. Can these be mocked and tested?

1 Answer 1

5

Here are some things I do to verify workflows that can be helpful in both the UI and in testmethods:

  1. Have as one of the workflow actions to create a completed Task for the target object record as in 'I, workflow X, have just done this useful thing' in the Task subject line. You can then look for the task in a testmethod.
  2. For key workflows, you could consider separate TextArea custom fields to log via Field Updates that the workflow did something with a useful dynamically-generated comment. This could also be verified in a testmethod.

Outbound messages simply won't execute in a test context - they are like outbound emails - never sent. hence, use the tasks or custom fields to record as a proxy for what the outbound message would have sent. This of course requires careful synchronization of the add task and send outbound email actions on each workflow.

3
  • good answer. Want to wait a couple days and see if anyone else has any input. If not I'll mark your as the answer
    – NSjonas
    Oct 3, 2014 at 13:35
  • 1
    what a great contribution - this use of Task is really juicy, and hopefully is the kind of thing that discourages people putting required fields and validation rules on activities! Oct 6, 2014 at 2:21
  • good point, required fields should be done via page layouts; validation rules should be recordtype aware for the above to work
    – cropredy
    Oct 6, 2014 at 16:40

You must log in to answer this question.

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