function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sgribisgribi 

VisualForce email template causes INVALID_CROSS_REFERENCE_KEY error for recipient.id

To notify idea contributiors to a new comment, we leverage an APEX call to deliver email messages to users that have contributed to the idea. The VisualForce email template includes Idea relevant content. All is well so far.

We wanted to add recipient specific content into the email. This worked when notifications are triggered by internal users, but failes when portal/community users trigger the same notifications. 
 
<messaging:emailTemplate subject="Vocera Idea was updated: {!relatedTo.Title}" recipientType="User" relatedToType="Idea">
<messaging:htmlEmailBody >
...
        Recipient...{!Recipient.Id}
...
</messaging:htmlEmailBody>
</messaging:emailTemplate>



After some trial and error, we found that adding {!recipient.id} (or any other recipient attribute) into the template would cause an INVALID_CROSS_REFERENCE_KEY error. 

I have to believe that this relates to User Sharing settings, where we limit portal user's ability to see all other portal users. Has anyone found a method to access the recipient.id (which is a user id) in a VisualForce template (for any user), when sending as a portal user?

With the recipient user id, I can call a component to do the Without Sharing magic and get any other relevant user attribute.