How to set up self-register for the community in Salesforce
Hi, Great to have you here. Today I am gonna show you how to set up self-register for the community with a custom component which allows any fields and validation that you want (see more about custom validation in Lightning in this article)
So let’s say you have already created your community (in case you don’t know how to do it – check out salesforce documentation ) and you are ready to start.
First what you need to do, is prepare a Profile and Account for your community User. So to do it navigate to Setup>Profiles>New and clone it from Partner Community User like below.
Then if you didn’t enable “Person Accounts” in your organization, you need to create a default Account for new users or use one of existing, otherwise, skip this step.
Okay, now we can start configuring our self-register for the community, so do it, go to your community and open the “Administration” panel, then go to the tab “Members” and from internal profiles add “System Administrator” and your newly created profile to selected profiles. Click Save.
Still in the “Administration” panel, select the “Login & Registration” tab and scroll to the “Registration Page Configuration”. In this section select “Allow external users to self-register” checkbox, then in “Registration Page Type” select Community Builder Page and in lookup select Register. At the end here fill “Profile” and “Account” fields with these you have created before (If you enabled Person Accounts, then leave “Account” blank). Click Save.
Now when self-register for the community is enabled we have all what is necessary to allow users for self-registration, so open link to your community in an incognito window (to see login page as a logged-out user), notice “Sign Up” button in the bottom right corner, when you click it, you should see something like below:
So now to test it, provide some data (remember to provide an email that doesn’t already exist in org) to click “Sign Up”. you should get a success message on the screen and email message with a link on your mailbox. Mission Accomplished
We could leave it as it is or add more fields through fieldSet in component attributes, but I want to show you how to use a custom component to completely justify this content.
To do it go to Setup>Lightning Components, select selfRegister aura component and open it in the developer console. What we want to do here is make a copy of this component bundle and name it SelfRegisterCustom (It is not a good practice to modify standard component). After that, we do the same for the apex controller, so open LightningSelfRegisterController class copy it, create z_LightningSelfRegisterControllerCustom, paste code from clipboard and replace all occurrences of “LightningSelfRegisterController” in this class to “z_LightningSelfRegisterControllerCustom”. Now when you have done it, open SelfRegisterCustom and notice a comment on the top of the file which says you need to add “implements=”forceCommunity:availableForAllPageTypes” to your component, so let’s do it and also replace controller to your new apex class, save. After that, the first line of your component should look like below:
<aura:component controller="z_LightningSelfRegisterControllerCustom" implements="forceCommunity:availableForAllPageTypes">
Okay, now go back to your community builder and open Register page, then replace “Self Registration” component with custom component “Custom Self Register”, you shouldn’t notice any difference in the look, but now any change in your custom component will affect to self-register look, you can, for example, use it to set up custom validation for data provided by user.
I hope this article will help you in setting up self-register for the community, Thank you for reading.