I'm not totally sure why the recipient is not taking the owner field from the record. I set up a scenario where I have the following:
Selected Recipients
My Custom Object Owner
Then took the following actions
- As User 1 set the owner to User 2 and saved record.
- As User 1 change the status to Assigned and saved record
- Received email with recipient.Name set to User 1 even though the record owner was User 2.
Perhaps I'm misunderstanding something about the usage of Owner in this scenario, but it isn't obvious to me. I expected the recipient.Name to come from the owner field.
You can get around it by using the relatedTo
merge field.
<messaging:emailTemplate subject="Status of My Custom Object Changed" recipientType="User" relatedToType="My_Custom_Object__c">
<messaging:plainTextEmailBody >
Recipient Fields:
recipient.Name: {!recipient.Name},
recipient.FirstName: {!recipient.FirstName}
recipient.LastName: {!recipient.LastName}
RelatedTo Fields:
relatedTo.Owner.Name: {!relatedTo.Owner.Name}
relatedTo.Owner.FirstName: {!relatedTo.Owner.FirstName}
relatedTo.Owner.LastName: {!relatedTo.Owner.LastName}
</messaging:plainTextEmailBody>
</messaging:emailTemplate>
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:
- Change the field update in the approval process step to 're-evaluate workflow after update' and
- Remove the email alert from the approval process step's action list and
- 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.
Best Answer
When using Enhanced Email, sending an email is a triggerable event, but there are some considerations. See https://help.salesforce.com/articleView?id=emailadmin_enhanced_email_considerations.htm&type=5 for more information.