Implement Custom Self-Registration for a B2B Store
Implement automated customer self-registration for Salesforce B2B Commerce storefronts using a custom Lightning Web Component and an Apex controller that orchestrates user provisioning, account creation, buyer access, and permission assignment.
The self-registration solution consists of two primary components:
- Custom web component — Provides the user-facing registration interface with form validation, user feedback, and storefront integration.
- Custom Apex controller — Orchestrates backend operations including user provisioning, account creation, buyer access configuration, and permission management.
Use this implementation when you want to:
- Enable customers to register for B2B Commerce stores without administrator intervention.
- Support password-based user authentication.
- Maintain control over user provisioning and account creation workflows.
- Enforce data validation and business rules during registration.
- Automate buyer access setup and permission assignment.
- Streamline the customer onboarding experience.
Customize the store’s registration page using custom Lightning Web Components (LWC) and Apex code. For a sample Apex class, see the CommerceSelfRegistrationController.cls class.
Before you begin:
-
Add the new UI component to your store’s self-registration page.
a. In the navigation sidebar, select a store from the Store dropdown.
b. Select Website Design, and then click Experience Builder.
c. In Experience Builder, go to the Self-registration page.
d. To view the properties, click the page.
e. Drag and drop the component on the page.
f. Configure the component properties.
g. Publish your store.
-
Grant
CommerceSelfRegistrationController.clsaccess to guest users.
Note: Grant guest users access only to the Apex classes required for self-registration. Don’t grant access to unrelated classes or classes that expose sensitive operations.
Don’t grant access to unrelated classes or classes that expose sensitive operations.
a. In the navigation sidebar, select a store from the Store dropdown.
b. Select Website Design, and then click Experience Builder.
c. In Experience Builder, go to Settings, and then click General.
d. Click the Guest User Profile.
e. In the Enabled Apex Class Access section, click Edit.
f. Add the Apex class to the list of enabled classes, and save your changes.
The CommerceSelfRegistrationController class is the core backend component that handles all server-side operations for customer self-registration.
The following sample shows a CommerceSelfRegistrationController class implementation.