Wednesday, October 9, 2019

How to set and reset the password using Apex in Salesforce

This post explains how to set and reset the password using apex in salesforce

Reset Password

Demo
resetPassword method accepts two parameters
Id (UserId): Id of the user
Boolean: it represents the send email to user or not
System.resetPassword(Id.valueOf('005B0000005lewT'), true);
when you run the above code, salesforce sends a password reset link to the user

Set Password

Demo
setPassword method accepts the two parameters
Id (UserId): Id of the user
String: new password value.
System.setPassword(Id.valueOf('005B0000005lewT'), 'test@12345');
when you run the above code salesforce will set the new password to the user.

No comments:

Post a Comment