3
  1. Two step approval process on custom object Foo__c
  2. initial value of Foo__c.Status__c is 'Submitted'

Approval Step 1 actions are threefold:

  1. Field update on Foo__c.status__c = 'Step 1 approved'
  2. Text email alert to recipient list with text body of: Status: {!Foo__c.status__c}
  3. VF email alert as shown below:

    <messaging:emailTemplate subject="some subject" recipientType="User" relatedToType="Foo__c">
      <messaging:htmlEmailBody >
        <html>
          <apex:outputText value="Status:"/>
          <apex:outputText value="{!relatedTo.Status__c}"/>
        </html>
      </messaging:htmlEmailBody>
      <messaging:plainTextEmailBody >
         Status: {!Foo__c.status__c}
      </messaging:plainTextEmailBody>
    </messaging:emailTemplate>
    

Although SFDC doc says that Field Updates execute before Email Alerts in a Workflow, I get the following results:

  • Email sent to next step (2) in approval process, email template includes Status = 'Step 1 Approved' [expected result]
  • Text-based email sent to recipient with Status = 'Step 1 Approved' [expected result]
  • VF email sent to recipient with Status = 'Submitted' [?!? not expected result]

I don't get it.

  • Why would the text-based email emitted in Approval Process Step 1 action contain the new (and correct) Field Update value but the VF-based email emitted in the exact same Approval Process Step 1 action does not have the new value?
  • It is as if SFDC sends off the VF-based email before the field update has processed contrary to expectations.
  • Reproduced by SFDC developer support in their own org; their remark: ...It is really weird behavior and I am escalating this to backline engineers to get resolution. – cropredy Jan 9 '14 at 1:38
  • SFDC engineering acks the issue, SFDC support says: "As of now we are not sure whether it is a WAD or known issue with salesforce, if WAD then the document help.salesforce.com/… must be corrected." – cropredy Jan 17 '14 at 20:20
  • Workaround suggested by SFDC support (but not yet tried by me): In approval process, rather than using an email alert, create a workflow rule on Status update (ex: when status equals 'Approved-step1') and create a workflow action to send an email alert(using VF template). Important thing is, you need to select 'Re-evaluate Workflow Rules after Field Change' on field update under approval process. – cropredy Jan 17 '14 at 20:22
2

SFDC developer support confirms that if you do a field update in an Approval Process step action and also have a VF (not text/HTML) email alert in the same approval process step action, that VF email alert will NOT merge in the updated-from-the-Field-Update value into the VF template. This is contrary to the doc which states that field updates occur prior to email alerts.

Note that text/html email alerts will merge in the updated-from-the-Field-Update value into the generated email.

The workaround, which I confirmed, is to:

  1. Change the field update in the approval process step to 're-evaluate workflow after update' and
  2. Remove the email alert from the approval process step's action list and
  3. Create a normal workflow on your target SObject that tests for the value of the field update in #1 and includes an email alert for your VF email template.

Note that if you do a field update in step i of an approval process, the new value of the field WILL BE available to the email sent to the approvers in step i+1. It is only intrastep VF email alerts that don't get the new value of that step's field updates.

If SFDC support notifies me that this is working-as-designed, expect a doc update; if it is a bug, expect it to appear on Known Issues.

Update - SFDC R&D says this is working as designed -- here is their explanation:

R&D explanation:

########## CAUSE: The VF template queries the database to retrieve the field data, but the TEXT/HTML template shares the Entity > Object (Java) from the Workflow to merge the field data.

SOLUTION/WORKAROUND:

############## customer has 2 solutions here.

Either 1)Customer can use TEXT/HTML email template instead of VF template in approval process OR 2) Remove email alert(which uses VF template) from approval process and implement the workflow action to send an email alert(with VF template) when the status field changes. Need to select 'Re-evaluate Work flow Rules after Field Change' on field update under approval process.

Personally, I think this explanation needs to be added to the doc as it is counter-intuitive to think that VF email templates associated with WF alerts won't behave the same as text/HTML email templates with the same WF alert.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.