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.
Headless Forgot Password JavaScript Examples
The Headless Forgot Password Flow contains two requests to the same endpoint. You initialize the flow with a request to Headless Forgot Password API. Here’s a function that you can call to initialize the password reset.
1//This is the function call to initialize the forgot password request
2forgotPasswordRequest(username, null, null, recapchaToken, forgotPasswordProcess.init, callbackFunction);This request results in Salesforce sending the user a one-time password (OTP).
For the second request, you pass the username, new password, and OTP to Headless Forgot Password API. Here’s a function that you can call to complete the password change.
1//This is the function call to complete the forgot password request
2forgotPasswordRequest(username, password, otp, null, forgotPasswordProcess.changePassword, callbackFunction)Because both requests call the same endpoint, you can use one function for both calls.
1function forgotPasswordRequest(username, password, otp, recapchaToken, forgotPasswordProcessStep, callbackFunction) {
2 client = new XMLHttpRequest();
3 client.open("POST", expDomain + forgotPasswordURI, true);
4 client.setRequestHeader("Content-Type", "application/json");
5
6 requestBody = {
7 username: username,
8 newpassword: password,
9 otp: otp,
10 recaptcha: recapchaToken
11 }
12
13 client.send(JSON.stringify(requestBody));
14
15 client.onreadystatechange = function() {
16 if(this.readyState == 4) {
17 if (this.status == 200) {
18 callbackFunction(JSON.parse(client.response), username, forgotPasswordProcessStep)
19 } else {
20 this.onError("An Error Occured during Forgot Password Step: " + forgotPasswordProcessStep, client.response);
21 }
22 }
23 }
24 }