BACKGROUND
I have a Visualforce email template does not always fully merge correctly.
Scenario 1: Via Setup - SUCCESS
Using the Send Test and Verify Merge Fields button in Setup, the email merges and sends correctly.
Scenario 2: Manually trigger Process Builder - SUCCESS
When I update the Booking__c
status to Confirmed it triggers a Process Builder process which calls an InvocableMethod
and the email merges and sends correctly.
Scenario 3: RestResource Controller triggers Process Builder - FAILING
- Request comes into a
RestResource
controller, the apex code updates anInvoice__c
object - Triggers a Process Builder process, which calls an
InvocableMethod
which updates theBooking__c
status to Confirmed - Triggers a Process Builder process to send the emails via the same
InvocableMethod
used in Scenario 2, but therelatedTo
fields do not merge.
The recipient
fields merged correctly, but the relatedTo
fields do not.
Testing
I added this code to see if the relatedTo
object wasn't available to the template at the point of merging:
<p>
{!recipient.Id }
</p>
<p>
{!relatedTo.Id }
</p>
<p>
{!relatedTo.Name }
</p>
And the IDs and NAME do appear in the failing email, but the rest of the merge fields do not.
0034E00000hn5OfQAI
a0C4E000003YmGlUAK
APPT-000367
Additionally, I tried replacing the broken email template with a working template, and that also failed to merge correctly.
Therefore, I am assuming it is not an issue with the email template markup or merge fields.
But rather an issue with the chaining of the Process Builder processes and Apex calls...
QUESTION
Why would the relatedTo
fields not merge correctly in Scenario 3?