You are here:
Customize the Self-Registration Apex Controller
For even more control, you can customize how customers and partners register for your site by modifying the default self-registration controller or by replacing it with your own custom controller. You can customize the self-registration controller regardless of which page type you're using.
Required Editions
| Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience |
| Available in: Enterprise, Performance, Unlimited, and Developer Editions |
| User Permissions Needed | |
|---|---|
| To create an Experience Cloud site: | Create and Set Up Experiences AND View Setup and Configuration |
| To customize or publish an Experience Cloud site: |
|
You can generate your own registration form by modifying the CommunitiesSelfRegController and the associated
CommunitiesSelfReg Visualforce page. You
use this single Apex controller regardless of which registration page type you
choose. The customizations you make in CommunitiesSelfRegController override the Login & Registration
page settings. In orgs created before the Spring ’15 release, existing Apex
customizations for self-registration remain in effect. You also use the CommunitiesSelfRegController controller to
implement multiple sites. Then you direct users to the appropriate start URL for
each site.
You can add, edit, or delete Apex using the Salesforce user interface only in a
Developer Edition organization, a Salesforce Enterprise Edition trial organization,
or sandbox organization. In a Salesforce production organization, you can change
Apex only by using the Metadata API deploy call,
the Salesforce Extensions for Visual Studio Code, or the Ant Migration Tool. The
Salesforce Extensions for Visual Studio Code and Ant Migration Tool are free
resources provided by Salesforce to support its users and partners, but are not
considered part of our Services for purposes of the Salesforce Main Services
Agreement.
- From Setup, in the Quick Find Box, enter Apex Classes, and then select Apex Classes.
-
Next to
CommunitiesSelfRegController, click Edit. -
(Optional) To define which profile to assign to the user, enter a value for the
ProfileId. - If you're using a business account, enter the account ID for the partner or customer account that users who self-register are associated with.
- If you're enabling self-registration for multiple sites, add code to assign the correct profile, role, and account ID to each site.
- Save your changes.
-
Enable access to accounts and contacts for the guest profile. The guest profile
is automatically associated with your site.
- From Setup, in the Quick Find box, enter All Sites, and then select All Sites.
- Next to your site name, click Workspaces.
- Select Administration, and then select Pages.
- Under Advanced Customizations, click Go to Force.com.
- Click Public Access Settings, then click Edit.
- Under Standard Object Permissions, next to Accounts, select Read and Create.
- Repeat the previous step for Contacts and save your changes.
- Under Enabled Apex Class Access, click Edit.
-
Add
CommunitiesSelfRegControllerto Enabled Apex Classes, and save your changes. - Under Enabled Visualforce Page Access, click Edit.
-
Add
CommunitiesSelfRegto Enabled Visualforce Pages, and save your changes.
- Test your self-registration process.
When setup is complete, customers and partner users who submit the completed self-registration form are logged in to the site.
