---
schema_version: "1"
id: a0bde37f415350bd2807d35ddb2d5b355b732678742d7832957a5e90d016f160
title: Create a Custom One-Time Password Delivery Apex Handler
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/custom_otp_provider_create_apex.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.custom_otp_provider_create_apex.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 4574fc2a3239697a64c090794591807140223ff6aca0478217c9fe968b8e2c95
description: 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.
products:
  - Security
  - Cross Cloud
release: "264"
---
# Create a Custom One-Time Password Delivery Apex Handler

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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Professional</strong>, <strong>Enterprise</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:74%">
          <col style="width:26%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d44791e52">User Permissions
              Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d44791e52 "><span id="custom_otp_provider_create_apex__class_perm_text"><a name="custom_otp_provider_create_apex__class_perm_text"><!-- --></a>To define, edit, delete, set security, and set version
                settings for Apex classes:</span></td>
            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d44791e52 "><span id="custom_otp_provider_create_apex__apex_perm_value"><a name="custom_otp_provider_create_apex__apex_perm_value"><!-- --></a>Author Apex</span></td>
          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d44791e52 "><span id="custom_otp_provider_create_apex__class__runtest_perm_text"><a name="custom_otp_provider_create_apex__class__runtest_perm_text"><!-- --></a>To run Apex tests:</span></td>
            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d44791e52 "><span id="custom_otp_provider_create_apex__apex_runtest_perm_value"><a name="custom_otp_provider_create_apex__apex_runtest_perm_value"><!-- --></a>View Setup and Configuration</span></td>
          </tr>
        </tbody>
      </table>

The custom OTP delivery handler uses the `sendOneTimePassword` method to send an OTP to the user.

1. From Setup, click ![Settings gear icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-xcloud-identity-264-0-0-production-enus/699dab6f-8f1a-4662-b24f-6521d5b747f7/resources-global/_corporate/images/gear.png), and then select **Developer Console**.
2. Click **File**, select **New**, and then select **Apex Class**.
3. Enter a name for your handler, such as `MyCustomOtpHandler`.
4. Develop an Apex handler that implements the `Auth.CustomOneTimePasswordDeliveryHandler` interface and returns an instance of the `Auth.CustomOneTimePasswordDeliveryResult` enum.
5. 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](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing.htm).
6. Save the handler.

Next, add the handler to your Experience Cloud site settings.