[SalesForce] username not populating in Email template ({!Receiving_User.Username}) customer portal

I am working on communities customer portal. I have created a email template for reset password for customer. when ever email triggered username is blank
for username am using :{!Receiving_User.Username} merge field
if i replace it with : {!user.username } it populating current user username but i need customer username please help me on this

FYI: For portal users, the Receiving_User is actually pulling fields from the Contact object, not from the User object. Even the standard fields are from the Contact, not from the User.

bellow is my code:

Dear {!Receiving_User.FirstName} {!Receiving_User.LastName}, —-> first name and last name populating correct

Username:{!Receiving_User.Username}

Login with temporary password link generated by system:{!Community_Url}

Please log into your account with the credentials listed above. You will be asked to set a new password when you log in. If you have any questions, please contact me.

Best regards,
{!User.FirstName} {!User.LastName}
{!User.Title}
{!User.Phone}
{!User.Email}
{!Organization.Name}

Best Answer

As you pointed out, the Receiving_User is actually a Contact object - this means there is no Username field on that Object. Depending on how you set up your users, I would assume that the Email field is actually used for generating usernames for customers. In this case, you can just change {!Receiving_User.Username} to {!Receiving_User.Email} and this would be merged with the user's username.

If that is not working, what you might do is use a visualforce template with an apex:component, supply the {!Receiving_User.Id} to the component's controller, query for the User with that ContactId and then return this User.Username to the VF-Email.