0

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?

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, Label.site.passwords_dont_match);
            ApexPages.addMessage(msg);
            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;        
         account.SPBE__Email__c=email;
         insert account;         

         account.OwnerId=Owner;
        // account.isPartner=true;

         update account;
         AccountNumber=account.Account_Number__c;
        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.CompanyName=CompanyName;
        u.Phone=fPhone;
        u.SPBE__City_Office__c=CityOffice;
        u.SPBE__State_Office__c=StateOffice;
        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;
                page.setRedirect(true);
                return page;
            }
        }
        return null;
    }
}
0

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

{!Community_Url}

| improve this answer | |
  • Can you explain your answer? What this expression will do? – LetMeCodeYou Aug 16 '18 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.