2

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

  1. Request comes into a RestResource controller, the apex code updates an Invoice__c object
  2. Triggers a Process Builder process, which calls an InvocableMethod which updates the Booking__c status to Confirmed
  3. Triggers a Process Builder process to send the emails via the same InvocableMethod used in Scenario 2, but the relatedTo 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?

  • Can you post email template code, editing your question. I think in the 3rd scenario, data is not committed, before sending the email which is asynchronous process – Santanu Boral Jul 26 '18 at 10:02
  • @SantanuBoral all the information that is being merged into the email already exists. None of the merge fields are recently added data. – Robs Jul 26 '18 at 10:08
0

The issue was caused by the permissions of the Site Guest User which is hosting the RestResource

The initial request comes via a RestResource controller which is hosted on a Site which is publicly available, so therefore the permissions of the Site Guest User control which fields are available when the Visualforce engine processes the email template merge fields.

By giving the Site Guest User read permissions on a few fields, the email template now merges correctly.

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.