[SalesForce] Community Welcome Email Merge Fields Not Merging

I am sending the community welcome email after a portal guest user completes a custom registration form.

The welcome email is a visualforce email template, with the recipientType as User and relatedToType as Account:

<messaging:emailTemplate subject="Welcome to X" recipientType="User" relatedToType="Account">
    <messaging:htmlemailbody>

        <p>Dear {!relatedTo.FirstName},</p>

        <p>Username: {!recipient.Username}</p>

        <a href="https://x.x.force.com/x/s/email-verification?id={!relatedTo.Id}">click here</a>

    </messaging:htmlemailbody>
</messaging:emailTemplate>

And I've tried with the relatedToType as Contact

<messaging:emailTemplate subject="Welcome to X" recipientType="User" relatedToType="Contact">
    <messaging:htmlemailbody>

        <p>Dear {!relatedTo.FirstName},</p>

        <p>Username: {!relatedTo.Email}</p>

        <a href="https://x.x.force.com/x/s/email-verification?id={!relatedTo.AccountId}">click here</a>

    </messaging:htmlemailbody>
</messaging:emailTemplate>

The community guest login profile has Read and Create permissions on both Account and Contact objects, and User gets created successfully.

Yet none of the fields gets merged into the email.

Also, when I create the user using Apex as the Admin user, the fields do not get merged either.

Questions

  1. What am I doing wrong?
  2. How can I fix it, such that the merge field values appear?
  3. Why are two emails being sent?

Best Answer

Community Merge Fields are not the same as Contact merge fields and are different merge fields than normal merge fields. You need to use the merge fields allowed for Communities. Examples - try these:

{!Community.Name} {!Receiving_User.Username} {!EmailVerify_Url}

Ref: https://help.salesforce.com/articleView?id=merge_fields_communities.htm&type=5

Related Topic