Time-Based Workflow: Apex Trigger Processing and Governor Limits

We recently documented a new time trigger processing “gotcha” in a Summer ’11 patch, and this one is especially important if you design your time-based workflow in conjunction with Apex triggers.

Contrary to what you might think, time-dependent actions aren’t executed independently.  They’re processed several times every hour, when they’re grouped together and executed in a single batch.  As a result, any Apex triggers that fire as a result of those grouped actions are also executed in a single batch.  This behavior can cause you to exceed your Apex governor limits.

For example, the 10 callouts per request limit could be applied against a batched execution of Apex triggers if your time-based workflow rules kick off Apex triggers that call an @future method that has a callout; you’ll hit the limit when more than 10 objects go into one queue.

Some folk have hit their governor limits and felt they shouldn’t have, assuming that time triggers execute one-by-one.  Because actions and triggers are processed in batches, realize that you might hit your limits when you didn’t expect to.

We’re working on enhancing how the workflow queue is processed, and as we mentioned at Dreamforce, in the future we’re planning to try to cut processing intervals down to as low as every 5 minutes.

To find out more about Apex governor limits, workflow limits, and how time-based workflow works, check out these helpful resources:

Leave your comments...

Time-Based Workflow: Apex Trigger Processing and Governor Limits