Nov 12, 2012

Using Business Time to Set Workflow Task Due Date

A couple of weeks ago I posted a hack that enables assigning a workflow task to a related user on the triggering object. This works with a class called WorkflowInstructions that parses a task descriptions and looks for a familiar string format (a "workflow instruction"). Once a workflow instruction is found, the class processes the workflow task according to the instructions.

Since the code allows processing of several types of workflow instructions, here is another useful use case... setting activity cto a certain number of business days from the case create date. For some reason, business hours is available in apex, but not when setting workflow tasks.

So here is what you need to add to the previous post code sample:
  • Add a business hours variable to hold your selected business hours record.
  • add 'businesstime' when checking for workflow instructions.
  • add a method that processes the 'businesstime' workflow instruction.

You still need the code for the trigger as in the previous post: And now, all you have to do to make the workflow work is to set up the workflow instruction in the description of the workflow task. The trigger will fire, then change the task activity due date, and then remove the instruction from the description. here is an example: