Custom one-time password (OTP) delivery relies on an Apex handler that implements the
Auth.CustomOneTimePasswordDeliveryHandler interface. Your
custom OTP delivery handler calls out to your provider to send an OTP to the user via SMS. You
can customize the content of the SMS message and the short code that the user sees.
Required Editions
| Available in: both Salesforce Classic (not available in all orgs) and Lightning
Experience |
| Available in: Professional, Enterprise, Unlimited, and
Developer Editions
|
| User Permissions
Needed |
| To define, edit, delete, set security, and set version
settings for Apex classes: |
Author Apex |
| To run Apex tests: |
View Setup and Configuration |
The custom OTP delivery handler uses the sendOneTimePassword method to send an OTP to the user.
- From Setup, click
, and then select Developer
Console.
- Click File, select New, and then select
Apex Class.
- Enter a name for your handler, such as
MyCustomOtpHandler.
- Develop an Apex handler that implements the
Auth.CustomOneTimePasswordDeliveryHandler interface and returns an instance of the
Auth.CustomOneTimePasswordDeliveryResult enum.
- To make sure that the handler can successfully call out to the provider to send an SMS
message, test the Apex handler with hard-coded values for the
userId, phoneNumber, oneTimePassword, defaultText, networkId, and experienceId. See Testing Apex.
- Save the handler.
Next, add the handler to your Experience Cloud site settings.