Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
CustomOneTimePasswordDeliveryHandler Interface
Namespace
CustomOneTimePasswordDeliveryHandler Methods
The following are methods for CustomOneTimePasswordDeliveryHandler.
sendOneTimePassword(userId, phoneNumber, oneTimePassword, networkId, defaultText, expId)
Signature
public Auth.CustomOneTimePasswordDeliveryResult sendOneTimePassword(Id userId, String phoneNumber, String oneTimePassword, String defaultText, Id networkId, String experienceId)
Parameters
-
userId:
Type: Id
ID of the external user.
-
phoneNumber:
Type: String
The user’s phone number. The phone number isn't necessarily verified by Salesforce.
-
oneTimePassword:
Type: String
The OTP that the user receives.
-
networkId:
Type: String
ID of the Experience Cloud site.
-
defaultText:
Type: Id
The content of the default SMS message that the user receives. You can create custom messages instead of sending the default. For example, write code to send custom messages based on the Experience Cloud site ID.
-
expId:
Type: String
A custom value that determines what the user experiences.
Return Value
CustomOneTimePasswordDeliveryHandler Example Implementation
1global class TelesignMessaging implements Auth.CustomOneTimePasswordDeliveryHandler{
2
3 global Auth.CustomOneTimePasswordDeliveryResult sendOneTimePassword(Id userId, String phoneNumber, String oneTimePassword,
4 String defaultText, Id networkId, String experienceId){
5
6 //Send the message from Telesign
7 HttpRequest request = new HttpRequest();
8 //The commented-out code on the next line isn't necessary if you use named credentials
9 //request.setEndpoint('https://rest-ww.telesign.com/v1/messaging');
10 request.setEndpoint('callout:Telesign_SMS_Named');
11 request.setMethod('POST');
12 String requestBody = 'is_primary=true&phone_number=' + phoneNumber + '&message='+'Custom OTP%20'+ oneTimePassword+';
13'+defaultText+'&message_type=OTP';
14
15 request.setHeader('accept', 'application/json');
16 request.setHeader('content-type', 'application/x-www-form-urlencoded');
17 //The commented-out code on the next line isn't necessary if you use named credentials
18 //request.setHeader('authorization', 'Basic <Base64-encoded Telesign customer ID:API key>');
19 request.setBody(requestBody);
20
21 HttpResponse response = new Http().send(request);
22 // Handle the response as needed
23 return Auth.CustomOneTimePasswordDeliveryResult.SUCCESS;
24 }
25}