Hello Trailblazers,
Have you ever found yourself in a situation where you need to reset passwords for multiple users? Well, fret not, as I have a solution for you!
The following code is a rough idea of how you can achieve this:
public class ChangePassword {
public ChangePassword() {
List<User> userList = new List<User>();
userList = [SELECT Id from User WHERE IsActive = true ];
for(User usr : userList) {
System.setPassword(usr.Id, 'xxxxxxxx');
System.debug('DONE: ' + usr.Id);
}
}
}
You can execute this code from the developer console. Here’s how:
- Select Debug
- Open Execute Anonymous Window
- Please execute:
ChangePassword ch = new ChangePassword();
Please note that I haven’t added an actual password in the code, so you will need to update “xxxxxxxx” with the password you want to set.
Happy Trails!