You are using an older browser that might negatively affect how this site is displayed. Please update to a modern browser to have a better experience. Sorry for the inconvenience!

Toggle CTA / link to reset the password in Community Welcome Emails


What is a Salesforce Community? 

Communities are used to collaborate with our customerspartners, and employees for various purposes. 

How to add users to the community? 

From the setup, search for All Communities; then, click on the corresponding community Workspaces 

In the workspace, click on Administration and then Members tab. In the members tab, we can add profiles and permission sets. 

Once the selected permission sets or profiles mentioned in the community members tab are added to the user, then the user is a member of that community. 

When will the users receive the Welcome Email in Community? 

If the settings of community “Send welcome email” is checked and upon activation of communityuser will receive a welcome email to Register or to Login the community for the first time and the users are suggested to create their password for the community login. 

What is a merge field? 

A merge field is a field used in the email templates to get the dynamic values and custom links from the Salesforce records. 

Purpose of merge fields: 

  1. $Network.NetworkUrlForUserEmails is used in the Visualforce email template which generates a link for the reset password page for the new community user. For the existing user, it redirects to the login page. 
  1. {!Community_Url} is used in the HTML email template which generates a link for the Forgot Password or Change Password page. 

Use case: Consider the Salesforce Org has multiple communities that share users across communities.  

What will happen actually? 

Upon activation of all community, a welcome email will be sent for all community users containing a CTA / link that suggests the users to reset the password before logging into the community. 

The modified business model: 

Since the users are same across the communities, we need to show the password setting link in the welcome email that delivered as first as part of activation a community. For rest of the communities, we need to hide the password setting link since the user created the password as part of welcome email sent in prior community activation.  

HTML email template vs Visualforce email template 

To toggle password setting link in welcome email, we can use Visualforce email template since this solution could not be achieved in HTML email. 

How to hide password setting link in Visualforce email template? 

The Visualforce email template has the accessibility to the password setting link ($Network.NetworkUrlForUserEmails) & NetworkMember can be accessed in Visualforce component which in turn can be embedded in Visualforce email template. 

[NetworkMember is a standard object which holds the property to check whether the current logged in user is a community member or not. By using this attribute, we are finalizing whether the user lands on community for the first time to register / to login to the community] 

Configurations to toggle the password setting link  

Step 1: To get the password setting link through the Visualforce email template and pass the link to the Visualforce component.  

Visualforce Email template: (CommunityWelcomeEmail.email)  

<messaging:emailTemplate subject=”Welcome to the Community” recipientType=”User” relatedToType=”NetworkMember“> 

    <messaging:htmlEmailBody >

<c:CommunityWelcomeEmail_VC userId=”{!recipient.Id}” userFirstName=”{!recipient.FirstName}” communityName=”{!$Network.Name}” communityUrl=”{!$Network.NetworkUrlForUserEmails}”/> 

    </messaging:htmlEmailBody> 

</messaging:emailTemplate> 

 Step 2: To show or hide the password setting link to the user in the Visualforce component based on the registration or login. 

Visualforce component: (CommunityWelcomeEmail_VC.vfc 

<apex:component controller=”CommunityWelcomeEmail_AC” access=”global”> 

    <apex:attribute name=”userId” type=”String” assignTo=”{!currentUserId}” description=”Id of the current user”/> 

    <apex:attribute name=”userFirstName” type=”String” description=”User first Name”/> 

    <apex:attribute name=”communityName” type=”String” description=”Current community Name”/> 

    <apex:attribute name=”communityUrl” type=”String” description=”Current community Url“/>      

    <table border=”0″ cellpadding=”5″ width=”600″ cellspacing=”5″ height=”400″ > 

        <tr valign=”top” height=”400″> 

            <td> 

                <div style=”padding-left: 12px”> 

                    <div>{!userFirstName},</div> 

                    <br/> 

                    Thank you for logging into the {!communityName} site. 

                    <br/> 

                    <apex:outputPanel rendered=”{!isExist}”> 

                        <br/> 

                        <div>To set your password, please click here:</div> 

                        <br/> 

                        <div style=”padding-left: 12rem”> 

                            <a href=”{!communityUrl}”>Create Password</a> 

                        </div> 

                        <br/> 

                        <div>After creating your password, please verify you can access the site. </div> 

                        <br/> 

                    </apex:outputPanel> 

Sincerely, 

{!communityName} 

                </div> 

            </td> 

        </tr> 

    </table> 

</apex:component>   

 Step 3: To check whether the current user already a member of any of the existing community. 

Apex class: (CommunityWelcomeEmail_AC.apxc)   

/* 

This Visualforce apex Controller used in Community welcome Emails to show (or) hide the Create Password link in the visualforce component. 

*/   

public without sharing class CommunityWelcomeEmail_AC { 

    public Boolean isExist; 

    public String currentUserId {get;set;} 

    public Boolean getisExist(){ 

        loadData(); 

        return isExist; 

    } 

    public void setisExist(Boolean isBool){ 

        isExist = isBool; 

    } 

    // This method return true, if the current user is not a member of any of the community. 

    public void loadData(){ 

        List<NetworkMembernetworkMembers = [SELECT Id,NetworkId,MemberId,Network.Name FROM NetworkMember WHERE MemberId =:currentUserId]; 

    if(networkMembers.size() > 1){ 

        isExist = false; 

    } else { 

        isExist = true; 

    } 

    } 

}