If you happen to encounter this problem "Error Occurred: invalid cross reference id" when the guest user tries to send an Email Alert with Visualforce Email Template via Flow Builder or Process Builder or any process automation tool provided by Salesforce, then you have come to the right place.

I have spent quite some time to realize this, so hopefully this post can save you some time.

Anyway in my case, this issue occurred is mainly due to an error when the guest user fails to access the object in the Visualforce Email Template. I searched online and tried to assign related object and field permissions to the site user profile but none of them are working.

At last, I came across this solution by adding renderUsingSystemContextWithoutSharing="True" attribute to the messaging:emailTemplate. Now, the guest user can sends the email without any error!

Here's the code snippet for your reference (Visualforce Email Template):

<messaging:emailTemplate renderUsingSystemContextWithoutSharing="True" subject="Account name: {!relatedTo.Name}"  relatedToType="Account">

This ensures that the Visualforce Email Template is running as System Mode which by default can access to all the fields regardless of the running user's permission.

I can't find the official documentation regarding the use of renderUsingSystemContextWithoutSharing, but somehow the online community seems to know about this hack.

Anyway, hope this post helps! See ya!

Post was published on , last updated on .

Like the content? Support the author by paypal.me!