Wednesday, October 28, 2015

Reset user password from APEX in case of user lockout

With winter 16 we have issue with password lockout when we have two factor enabled

Click here to see the issue

We are experiencing so many lockouts so I came up with this 

global class scheduledPasswordReset implements Schedulable {

 global void execute(SchedulableContext SC) {
Set<String> Ids = new Set<String>();
Set<String> LockIds = new Set<String>();
for (LoginHistory l : [SELECT UserId,LoginTime, status FROM LoginHistory WHERE LoginTime = TODAY ORDER BY LoginTime DESC  ]){
if(!Ids.contains(l.userId)){
Ids.add(l.userId);
if(l.status == 'Password Lockout'){
LockIds.add(l.userId);
}
}
}
system.debug('### '+LockIds);
for(String uId : LockIds){
 System.resetPassword(uId, true);
}

   }

}

Tips on passing Salesforce AI Associate Certification

  🌟 Motivation to Pursue the Salesforce AI Associate Certification 🌟 The world of technology is in a state of perpetual evolution, and on...