2

How to unlock a User with Apex/Soql? I don't want to use unlock User button.

Regards, Sandeep

5

You can unlock users via the UserLogin record.

UserLogin someDude = [SELECT IsPasswordLocked FROM UserLogin WHERE UserId = 'jndfgl9sfdg08fg'];
someDude.IsPasswordLocked = false;
update someDude;
  • So it's been possible since API version 29 (not new to this release)? – Adrian Larson Apr 29 '16 at 17:57
  • I believe so. You can also Activate and deactivate(Salesforce Delete) users from the User record as well. – TemporaryFix Apr 29 '16 at 18:03
  • If you are doing this just using SOQL in the DEV console, and manually unchecking the IsPasswordLocked flag, then you will also want to include the ID in the SOQL. – bpilling Jan 6 at 20:46
4

From the User Documentation

The password lockout status and the ability to reset the User locked-out status is not available via the API. You must check and reset the User password lockout status using the user interface.

  • This is possible in Salesforce 16, see my answer – TemporaryFix Apr 29 '16 at 17:49
1
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);  
}
  • This will pick the topmost status for the user it worked like a charm for the BUG we have in winter16 for 2FA login – Avijit Chakraborty Oct 28 '15 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.