+ Start a Discussion
Jonathan OsgoodJonathan Osgood 

Communities Self Reg

Hi All,

Configuring Communties self registration. After submitting new user login info, I  am redirected to an "Internal server error..." message (screenshot attached).  I have properly (I hope) updated the SelfRegController --adding a profile, role and account ID. Deployed to production with 85% Coverage and no problems. Also, the new user is correctly added to salesforce. 

Is this a navigation issue, perhaps?

Thank you!
PratikPratik (Salesforce Developers) 
Hi Jonathan,

Will you please post your modified SelfRegController code so we can help.

Thanks,
Pratik
Jonathan OsgoodJonathan Osgood
Hi Pratik,

Here is the full controller:
 
/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
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 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 = '00eU0000000jbMU'; // To be filled in by customer.
        String roleEnum = '00EU0000000eH5q'; // To be filled in by customer.
        String accountId = '001U0000009hywA'; // To be filled in by customer.
        
        String userName = email;

        User u = new User();
        u.Username = userName;
        u.Email = email;
        u.FirstName = firstName;
        u.LastName = lastName;
        u.CommunityNickname = communityNickname;
		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;
    }
}