In Salesforce is different, it is so secure, system admin and everyone else not able to see or modify any user password. But, as the best practice, we offer to reset their password, and Salesforce will send email to the user with instruction to set new password by their own, and it should works fine.
But again, some users (read: senior management) not really want to bother by checking email and so on, even the request is come from his/her secretary. So how? No problem, we can change user email to her secretary email, secretary confirm email change in her email (although Salesforce also will email to the original email say that the email has been changed to new one), and reset password. It works, yay!!!
But, how to change back the user email to the original one? The senior management need to click a link again in her email (she may have hundreds or thousands email never read). Problem.
So, I just start think if there is an easy way to set user password without have to go through such complicated process? It is worst when the user is going to present something in 5 minutes and we do not have much time to do above process. So, can we set user password?
YES, it is possible, this function is not exist in Salesforce setup menu, but Salesforce is kind enough to provide system administrator with Developer Console. Yes, Developer Console is for developer as it named, but admin also can use it for other purpose, like set user password, yay!!!
In this sample: 00550000000rlrX is the User Id, if you are Salesforce admin, you should now this Id well, and hello123 is the new password to set.
System.setPassword([SELECT Id FROM User WHERE username='joe@lazy.com'].Id, 'hello123');
Below sample code to set password of all active user in one go:
List<User> userList = new List<User>();
userList = [SELECT Id from User WHERE IsActive = true];
for (User u : userList)
{
System.setPassword(u.Id, 'hello123');
System.debug('DONE: ' + u.Id);
}
You can modify the SOQL above as needed, example: only for profile = "Sales Rep".
All statements above is apex code, but we can utilize it for other productive work as needed.
No comments:
Post a Comment