Create Custom Error Messages in the Login Discovery Handler
If a user makes a mistake when trying to log in to your site, the Apex handler displays
a generic error message. You can customize the error message that appears on the login page
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: |
|
- 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.LoginDiscoveryHandler.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 toAutocreatedDiscLoginHandler1535677786093. -
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.
Login Discovery custom error messages appear on the login page.