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

send password link on self registeration

I have made a controller of self user registration . and while doing this what i am trying to make is that when ever user registered a password link should be sent on user email id ,just like when ever we create a org and sales force send a email verification link on our email id. Is it possible to do so? If yes then How? Help me out Guys.!! Here is a Controller:-
public with sharing class CommunitiesSelfRegController {
public String firstName {get; set;}
public String lastName {get; set;}
public String email {get; set;}
public String password {get; set {password = value == null ? value : value.trim(); } }
public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
public String CompanyName { get; set; }
public String fPhone { get; set; }

public CommunitiesSelfRegController() {}

private boolean isValidPassword() {
    return password == confirmPassword;

public PageReference registerUser() {

       // it's okay if password is null - we'll send the user a random password in that case
    if (!isValidPassword()) {
        ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,;
        return null;

     String profileId = '00e90000001jxLE'; // To be filled in by customer.
     String roleEnum = 'Partner User'; // To be filled in by customer.
     String accountId = ''; // To be filled in by customer.
     String CityOffice='00590000003BnUR';
     String StateOffice='00590000003BnSa';
     String Owner='00590000003Bn3L';   // sytem Admin ID 
     String AccountNumber;
     Account account= new Account();
     account.Name =firstName;
     account.SPBE__First_Name__c= firstName;
     account.SPBE__Last_Name__c = lastName;        
     insert account;         

    // account.isPartner=true;

     update account;
    accountId = account.Id;
    String userName = email;
    User u = new User();
    u.Username = userName;
    u.Email = email;
    u.FirstName = firstName;
    u.LastName = lastName;
    u.CommunityNickname = firstName+AccountNumber;
    u.ProfileId = profileId;

    String userId = Site.createPortalUser(u, accountId, password); 

    if (userId != null) { 
        if (password != null && password.length() > 1) {
            return Site.login(userName, password, ApexPages.currentPage().getParameters().get('startURL'));
        else {
            PageReference page = System.Page.CommunitiesSelfRegConfirm;
            return page;
    return null;

Sagar PareekSagar Pareek
Have you configured any email template for this mail? Make sure email template needs to include this special merge field 

@sagar Pareek Thanx for ur response.I have tried  but noting happen. :( Help me out .
Sagar PareekSagar Pareek
Customize>Communities >All Communities

You will find small drop down button near your community name . click on administration settings a pop will open and there you will find your email template and make sure send welcome email check box is checked.

User-added image
@sagar Pareek i  have already done this but my  query is like  i dont want to give the user to set his own password while self registeration beacuse while doing this we cant verify the email address . and  fake users  will be  more. I just want to send an email verification link on his/her email id  and  whenever the user click on that particular link a passoword  link will open on his/her email id. Just like when ever a user registerd on Salesforce.