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
TrueOasisTrueOasis 

Visualforce Template - Communities Welcome Email - How to get {!Receiving_User.Username}?

Is there a way to get access to the username of the receiving community user while using a visualforce email template?  I am not finding the way to get this. 

With an HTML email template you simply have to use {!Receiving_User.Username}.  Visualforce email templates do not like this reference.

I have tried:
  • {!User.Username} - Wrong!  That's the sending user
  • {!Receiving_User.Username} - Template will not save.
    • "Error: Unknown property 'core.email.template.EmailTemplateComponentController.Receiving_User'
  • {!relatedTo.Username} - I can save the template but the result on receipt of the email is blank!
By the way, {!$Network.NetworkUrlForUserEmails} is working great.  

Here is a simple version of my template:

<messaging:emailTemplate recipientType="Contact"
    relatedToType="User"
    subject="Welcome!"
    replyTo="xxx@example.com">
    <messaging:htmlEmailBody >
        <html>
            <body>
                <p>Dear {!recipient.name},</p>
                <p>Your username is: {!Receiving_User.Username} </p> .  <----- DOES NOT WORK!
                <p><a href="{!$Network.NetworkUrlForUserEmails}">Click here to register now! </a></p>
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>
TrueOasisTrueOasis
Nobody knows?
Holly DurenHolly Duren
I am also running into this issue
Reinier van den Assum | DeloitteReinier van den Assum | Deloitte
I've ran into this issue last week as well, causing quite some time investigating documentation and such.
The solution: Proceed with a Custom HTML email. The only benefit missing in comparison to a VF Template is a more limited MergeField functionality (not able to do e.g. User.Contact.Name). However, based on your and my template, that does not seem to be causing an issue.

Your template would then be:
<html>
   <body>
      <p>Dear {!Receiving_User.FistName},</p>
      <p>Your username is: {!Receiving_User.Username} </p>
      <p><a href="{!Community.Url}">Click here to register now! </a></p>
   </body>
</html>
I've just tested this and the email was sent properly and all merge fields were populated.
Najmul Hasan 4Najmul Hasan 4
You need to set the recipientType="User" and relatedToType="Network" and then simply use the  {!recipient.Username} to get the receiving user's username in your email template dynamically.