Play Games

Search This Blog

Tuesday, May 10, 2022

How to freeze a salesforce user using apex code - SalesforceGlobe4U

How to freeze a salesforce user using apex code - SalesforceGlobe4U

Solution: Update the IsFrozen field to true on UserLogin object to freeze the user.

Example: Run the following piece of code from Developer console

String salesforceUserId = '00590000001OPI9';//replace with salesforce user id

List<UserLogin> lstUserLogin = new List<UserLogin>();

lstUserLogin = [Select id,UserId,IsFrozen from UserLogin where UserId =:salesforceUserId];

if(!lstUserLogin.isEmpty()){

lstUserLogin[0].IsFrozen = true;

update lstUserLogin;

System.debug('Frozen User :'+ lstUserLogin[0].IsFrozen);

}

Output:




No comments:

Post a Comment