+ Start a Discussion

Warning: Workflow Field Updates vs Visualforce Email Alert templates

Just thought I would alert the community to this issue in case anyone else falls into the same trap.


Please note that when referring to Workflow Actions here I am talking about Immediate Actions rather than Time-Dependent Actions. I have not tested how this is affected by Time-Dependent Actions because my Workflow criteria requires the "Every time a record is created or edited" option. If you don't need this option then Time-Dependent Actions may be a possible solution.




Anyone who does a lot of Workflow based work knows that when one executes it does so in the following order:


  1.      All field updates (although not in any specific order).
  2.      All other workflow actions (again not in any specific order).

You can find this in Salesforce's public documentation and are also taught it in the Advanced Administration courses.



           From: https://help.salesforce.com/HTViewHelpDoc?id=workflow_rules_considerations.htm&language=en_US )

          Quote: "The order in which individual actions and types of actions are executed is not guaranteed. However, field

                       update actions are executed first, followed by other actions."


Personally, I have put together a lot of Workflows that rely on this behaviour. Generally I have emails sent out that include the updated values of the record.


The Problem


Some time ago Salesforce added the ability to use Visualforce based email templates for Workflow Email Alerts. This is great but, rather unexpectedly, it breaks the above behaviour. The technical reasons are a bit complex but for all intents and purposes the new order is now:


  1.      All Visualforce based Email Alerts (not in any specific order).
  2.      All field updates (not in any specific order).
  3.      All other Workflow actions including non-Visualforce based Email Alerts (not in any specific order).

So, if like me, you want to enhance the utility of your Workflows by replacing your HTML/Custom templates with Visualforce templates you may get nonsense results.


The Solution


Salesforce are not going to fix this. Sorry, let me rephrase. Salesforce are not going to change this, as they have now declared that this is the behaviour-by-design [sighing smiles all round by those that have dealt with Support on technical issues].


Essentially you have these options:


  1.     Don't use Visualforce based templates if you require the updated field values to be in the email.
  2.     Use Before triggers to update the fields (since Before triggers are executed before Workflows).

If Time-Dependent Actions are available to your Workflows these may solve this problem. May be someone else can comment. 


Small Rant


This section is not important to the information above, feel free to not waste your time and stop reading.


As indicated I went through one of those typical support scenarios of spending an amazing amount of time (counting in weeks) and effort to essentially prove to Salesforce that their system was not working as advertised and pass me along to someone who understood the system technically enough to have a proper look at it. Within hours of the senior T3 tech taking over the case and stating that he was able to "replicate the scenario" I got back the dreaded "we are now declaring this to be the correct behaviour" comment. My big concern in this particular case though is that the UI provides no warning of this new "correct" behaviour and the documentation directly contradicts it. I was told that their documentation team had now been informed and that the documentation, at least, would be updated. My case closed over a month ago yet no updates (hence this post). Rant, rant. Sigh.


I hope this is helpful to someone.