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
Wei Dong 10Wei Dong 10 

Several Questions about Customized Self-Register

Hi all,
I have several questions during my dev of customize self-registeration:

1) I've created a Community called "https://dev-conagradev.cs65.force.com/readyseteat",  but to my surprise is that there's a suffix "/s"……Why? I cannot remove that at all. How can I remove that?
User-added image

2) I entered the "builder" of that to select a self-registeration page (My selection is "SelRegister"——A lightning page with some components):
User-added image

But to my surprise——When I run the page I always receive an error (See the red below), why? I do nothing to do codes at all.
Even if I tried to do some alerts, I didn't see anything popped up to me?No alert dialog pops out?
User-added image

In my Server-side code, where to see "System.Debug"? I see nothing outputted in the Developer Console……
User-added image

Is there any full example of using SelfRegister page to implement your own registeration step by step? Thanks!
Naveen KNNaveen KN
Hi Wei Dong, 

First issue:
This is product behavior, there is an idea submitted for the same. Upvote and comment it https://success.salesforce.com/ideaView?id=08730000000cKd5AAE

Second issue:
You are reporting that the 'init' method is not executed in the component load. can you post component code so that we can take a look on that?

While working on the lightning components always start debugging from the component side. 

Naveen
Team Codengine.in 
 
Wei Dong 10Wei Dong 10
Hi,
Thanks for your quick reply:

I did nothing to the codes (I mean the codes are auto generated):

【SelfRegisterController.js】
({
    initialize: function(component, event, helper) {
        console.log('initialize entered');
        $A.get("e.siteforce:registerQueryEventMap").setParams({"qsToEvent" : helper.qsToEventMap}).fire();
        $A.get("e.siteforce:registerQueryEventMap").setParams({"qsToEvent" : helper.qsToEventMap2}).fire();        
        component.set('v.extraFields', helper.getExtraFields(component, event, helper));
    },
    
    handleSelfRegister: function (component, event, helpler) {
        alert('handleSelfRegister from Controller entered');
        helpler.handleSelfRegister(component, event, helpler);
    },
    
    setStartUrl: function (component, event, helpler) {
        var startUrl = event.getParam('startURL');
        if(startUrl) {
            component.set("v.startUrl", startUrl);
        }
    },
    
    setExpId: function (component, event, helper) {
        var expId = event.getParam('expid');
        if (expId) {
            component.set("v.expid", expId);
        }
        helper.setBrandingCookie(component, event, helper);
    },
    
    onKeyUp: function(component, event, helpler){
        //checks for "enter" key
        if (event.getParam('keyCode')===13) {
            helpler.handleSelfRegister(component, event, helpler);
        }
    }   
})
【SelfRegisterHelper.js】
({
    qsToEventMap: {
        'startURL'  : 'e.c:setStartUrl'
    },
    
    qsToEventMap2: {
        'expid'  : 'e.c:setExpId'
    },
    
    handleSelfRegister: function (component, event, helpler) {
        var accountId = component.get("v.accountId");
        var regConfirmUrl = component.get("v.regConfirmUrl");
        var firstname = component.find("firstname").get("v.value");
        var lastname = component.find("lastname").get("v.value");
        var email = component.find("email").get("v.value");
        var includePassword = component.get("v.includePasswordField");
        var password = component.find("password").get("v.value");
        var confirmPassword = component.find("confirmPassword").get("v.value");
        var action = component.get("c.selfRegister");
        var extraFields = JSON.stringify(component.get("v.extraFields"));   // somehow apex controllers refuse to deal with list of maps
        var startUrl = component.get("v.startUrl");
        
        startUrl = decodeURIComponent(startUrl);
        
        action.setParams({firstname:firstname,lastname:lastname,email:email,
                password:password, confirmPassword:confirmPassword, accountId:accountId, regConfirmUrl:regConfirmUrl, extraFields:extraFields, startUrl:startUrl, includePassword:includePassword});
          action.setCallback(this, function(a){
          var rtnValue = a.getReturnValue();
          if (rtnValue !== null) {
              alert('selfRegisterError=== '+rtnValue);
             component.set("v.errorMessage",rtnValue);
             component.set("v.showError",true);
          }
       });
    $A.enqueueAction(action);
    },
    
    getExtraFields : function (component, event, helpler) {
        var action = component.get("c.getExtraFields");
        action.setParam("extraFieldsFieldSet", component.get("v.extraFieldsFieldSet"));
        action.setCallback(this, function(a){
        var rtnValue = a.getReturnValue();
            if (rtnValue !== null) {
                component.set('v.extraFields',rtnValue);
            }
        });
        $A.enqueueAction(action);
    },

    setBrandingCookie: function (component, event, helpler) {        
        var expId = component.get("v.expid");
        if (expId) {
            var action = component.get("c.setExperienceId");
            action.setParams({expId:expId});
            action.setCallback(this, function(a){ });
            $A.enqueueAction(action);
        }
    }    
})
Naveen KNNaveen KN
I see only javscript code here, can you please post component code. And also please confirm that it is not logging the things mentioned inside the method 'initialize' is it?
Wei Dong 10Wei Dong 10
Thanks Codeengin.in:
<!-- add implements="forceCommunity:availableForAllPageTypes" to surface the component in community builder -->
<aura:component controller="LightningSelfRegisterController">
    <aura:attribute name="accountId" type="String" required="false" description="accountId for creating the user. If not specified, it will create a PersonAccount if possible for B2C scenario. Or otherwise if it's in a community, the community's self-registration accountId will be used."/>
    <aura:attribute name="regConfirmUrl" type="String" required="true"/>
    <aura:attribute name="startUrl" type="String" required="false" description="The url you go to after a successful login" />
    <aura:attribute name="showError" type="Boolean" required="true" description="" default="false" access="private"/>
    <aura:attribute name="errorMessage" type="String" required="false" description="" access="private"/>
    <aura:attribute name="firstnameLabel" type="String" required="false" default="First Name"/>
    <aura:attribute name="lastnameLabel" type="String" required="false" default="Last Name"/>
    <aura:attribute name="emailLabel" type="String" required="false" default="Email"/>
    <aura:attribute name="passwordLabel" type="String" required="false" default="Create Password"/>
    <aura:attribute name="confirmPasswordLabel" type="String" required="false" default="Confirm Password"/>    
    <aura:attribute name="submitButtonLabel" type="String" required="false" default="Sign Up"/>
    <aura:attribute name="includePasswordField" type="Boolean" required="false" default="false" description="Whether to include password"/>    
    <aura:attribute name="extraFieldsFieldSet" type="String" required="false" description="A field set name whose fields are desired for user registration"/>
    <aura:attribute name="extraFields" type="list" required="false" description="A field set name whose fields are desired for user registration"/>
    <aura:handler name="init" value="{!this}" action="{!c.initialize}"/>
    <aura:attribute name="expid" type="String" required="false" description="The branding experience ID" />    
    
    <aura:registerevent name="sitePropagatedStartUrl" type="c:setStartUrl"/>
    <aura:handler name="init" value="{!this}" action="{!c.initialize}"/>
    <aura:dependency resource="c:setStartUrl" type="EVENT"/>
    <!-- Please uncomment
    <aura:dependency resource="siteforce:registerQueryEventMap" type="EVENT"/>
    -->
    <aura:handler event="c:setStartUrl" action="{!c.setStartUrl}"/> 
    <aura:handler event="c:setExpId" action="{!c.setExpId}"/>    
    <aura:dependency resource="c:setExpId" type="EVENT"/>   
    
    <div>
            <aura:renderIf isTrue="{!v.showError}">
                <div id="error">
                    <ui:outputRichText value="{!v.errorMessage}"/>
                </div>
            </aura:renderIf>
            <div id="sfdc_username_container" class="sfdc">
                <span id="sfdc_user" class="login-icon" data-icon="a"></span>
                <ui:inputText value="" aura:id="firstname" placeholder="{!v.firstnameLabel}" keyup="{!c.onKeyUp}" class="input sfdc_usernameinput sfdc"/>
            </div>

            <div id="sfdc_nickname_container" class="sfdc">
                <span id="sfdc_user" class="login-icon" data-icon="a"></span>
                <ui:inputText value="" aura:id="lastname" placeholder="{!v.lastnameLabel}" keyup="{!c.onKeyUp}" class="input sfdc_usernameinput sfdc"/>
            </div>

            <div id="sfdc_email_container" class="sfdc">
                <span id="sfdc_user" class="login-icon" data-icon="k"></span>
                <ui:inputText value="" aura:id="email" placeholder="{!v.emailLabel}" keyup="{!c.onKeyUp}" class="input sfdc_usernameinput sfdc"/>
            </div>
            
            <aura:iteration aura:id="extraFields" items="{!v.extraFields}" var="curField" indexVar="index">
                <div id="sfdc_extrafield_container" class="sfdc">
                    <span id="sfdc_user" class="login-icon" data-icon="a"></span>
                    <ui:inputText value="{!curField.value}" aura:id="{!curField.fieldPath}" placeholder="{!curField.label}" keyup="{!c.onKeyUp}" class="input sfdc_extrafieldinput sfdc"/>
                </div>
            </aura:iteration>

            <aura:renderIf isTrue="{!v.includePasswordField}">
                <div id="sfdc_password_container" class="sfdc">
                    <span id="sfdc_lock" class="login-icon sfdc" data-icon="c"></span>
                    <ui:inputSecret value="" aura:id="password" placeholder="{!v.passwordLabel}" keyup="{!c.onKeyUp}" class="input sfdc_passwordinput sfdc"/>
                </div>
    
                <div id="sfdc_confirm_password_container" class="sfdc">
                    <span id="sfdc_lock" class="login-icon sfdc" data-icon="c"></span>
                    <ui:inputSecret value="" aura:id="confirmPassword" placeholder="{!v.confirmPasswordLabel}" keyup="{!c.onKeyUp}" class="input sfdc_passwordinput sfdc"/>
                </div>
            </aura:renderIf>

            <div class="sfdc">
                <ui:button aura:id="submitButton" label="{!v.submitButtonLabel}" press="{!c.handleSelfRegister}" class="sfdc_button"/>
            </div>
    </div>
</aura:component>

PS:You can find the component inside a dev or sandbox's "c:selfRegister" control in the Developer Console and run directly to see the final result (I suspect whether I've missed something……)?
User-added image
Naveen KNNaveen KN
I see that there is initialize handler in your code  -> <aura:handler name="init" value="{!this}" action="{!c.initialize}"/>
so it should hit controller js file. Check in browser console whether you are seeing comments like  ''initialize entered''

Naveen

 
Wei Dong 10Wei Dong 10
Finally I see that when I change the code, the community has created a new component called "Custom Self Register" (I don't know why and I remember I didn't create it on purpose)……But when I drag and drop this into the component, it can OK. The codes are all below.

My another question is:  Why "Your Request cannot be processed"……Is there anythign wrong when calling "Site.createPortalUser"? Anything should be noticed?
Sai Bharadwaj GotetiSai Bharadwaj Goteti
Allow external users to self register in the communties settings by checking -->  Allow using standard external profiles for self-registration and user creation.
Setup
--> All Communties --> open the Builder of your communty --> Settings --> General -->  Guset User Profile --> Add the Apex Class (LightningSelfRegisterController) related to the Self Registration.

Hope this helps.