Monday, April 14, 2014

Salesforce Gotcha! Time-Based Workflow Nuance

I received a complaint that a certain time-based workflow was not firing consistently. I looked at the workflow in question.  This was created by one of the Salesforce Certified consultants earlier on. In summary, it works like this:

Workflow A: evaluated when record is created, or edited and subsequently meets criteria
Condition: Status is X
Immediate Action: Set a Future Fire Date to Today() + 240
Time-Based Action: Send email 1 hour after Future Fire Date

On the surface, this sounds logical.  It even works from time to time.  I checked all records with Status X and they all are in the time-based workflow queue.  But thinking about previous implementations, we know that Salesforce does not guarantee order of execution of workflow actions. So it is possible that the time-based action is being put into the queue, but the Future Fire Date is still blank, in which case, it will not be added to the queue.

I searched the Knowledge Base for more information.  The Time-Based Workflow FAQ did not have definite information about it.  I ended up opening a case with Salesforce Premiere Support.  They confirmed that the above workflow will NOT consistently work.

This is why the Field Update has a new feature to trigger workflow rules after the update.

The correct solution then is to break the workflow above into two:

Workflow A: same as above
Condition: Same as above
Immediate Action: Set a Future Fire Date to Today() + 240
Check the flag on the Field Update to Trigger Workflows

Workflow B: evaluated when record is created, or edited and subsequently meets criteria
Condition: Future Fire Date is not null  (or Status is X)
Time-Based Action: Send Email 1 hour after Future Fire Date

This will now work consistently and no records will be missed.

No comments:

Post a Comment