If a user makes a mistake when trying to self-register for your site, the Apex handler
displays a generic error message. You can customize the error message that appears on the
self-registration page and verify pages using the Auth.DiscoveryCustomErrorException exception.
Required Editions
| Available in: Salesforce Classic and Lightning Experience |
| Available in: Enterprise, Performance, Unlimited, and Developer Editions |
| User Permissions Needed | |
|---|---|
| To access Experience Workspaces: |
|
| To create and edit Visualforce pages: | Customize Application |
| To edit Apex classes: |
|
If you selected the Email or Text Message verification methods when you configured self-registration, custom error messages appear on the verify page. If you selected None for the verification method, the error message appears on the self-registration page.
- From Setup, in the Quick Find box, enter Apex, and then select Apex Classes.
- From the list of Apex classes, find the class that implements
Auth.ConfigurableSelfRegHandler.You can find the name of the handlers on the Login & Registration page of the Administration workspace. If you haven’t renamed the handler, the name is similar toAutocreatedConfigSelfReg1532475901849 - To add the custom error message, edit the Apex class using the
Auth.DiscoveryCustomErrorExceptionexception.For example,throw new Auth.DiscoveryCustomErrorException('Custom error message defined by the admin.'). - (Optional) Instead of entering the custom error message in the Apex class, you can create
the error message as a custom label.
Custom labels are custom text values that can be translated to the user’s native language. In this example,
CustomErroris a custom label.throw new Auth.DiscoveryCustomErrorException(Label.CustomError)
Note You create a custom error message from the Custom Labels Setup page. The error message can be up to 200 characters.