We are having several VF templates that are used in an email alert in a Process.
When we trigger the Process from Apex, then the Process is run, but the email template is not merged properly (even though it is sent to the proper email address): the recipient and the relatedTo are not resolved, so all merge tags show empty. Using workflows instead of a Process yields the same negative result.
My observations:
- The templates merge fine when we test them manually (i.e. without triggering the Process, but do a test-and-verify)
- The templates merge fine when we trigger the Process through the UI (i.e. we edit a record via the UI, the Process runs)
- The templates DO NOT merge when we trigger the Process/Workflow from Apex code (i.e. we edit the record via Apex)
Can anybody confirm this and/or share a solution? Thanks!
For reference, this is the simplest email template I could produce:
<messaging:emailTemplate subject="TEST" recipientType="Contact" relatedToType="Check__c">
<messaging:htmlEmailBody >
Hey {!relatedTo.Guest__r.FirstName}
</messaging:htmlEmailBody>
</messaging:emailTemplate>
Then we have an email alert that is based on this email template, and that sends the email to Related Contact: Guest
.
Then either a Workflow or a Process sends an email alert, from a Check__c
record that has Check__r.Guest__c
definitely filled in. The email is sent to the proper email address.
Yet, what is generated is "Hey " and not "Hey Frank" (or any other name).