function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kiran456Kiran456 

Is it possible to trigger behaviour of forgot password of salesforce through apex?

Is there any system method which triggers forgot password through apex. I am not talking about System.resetPassword(<UserID>,<isMailToBeSentOrNot>). Because this will directly take user to the page where user would be asked to enter new password. I want user should be taken to a page where security question is asked and then password is reset.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
As far as I'm aware, you can't invoke this behavior. In Apex Code, you can either use Site.forgotpassword or System.resetpassword, both of which have the same effect; they will cause the system to issue a new password immediately to the email address on the user account.

Keep in mind that users can't log in outside of a known address range unless their computer is authenticated (identity verification), so asking for the security question is largely unnecessary.

The only eventuality I could see where this might be a problem is if the user has verified their computer's identity, stored their email password, and didn't have a password on their local user account, and then it was stolen. In this case, the appropriate action to secure the account would to change the email password, then reset the user's password (and, depending on the email system, expire current sessions, such as in Gmail).