Users Freeze or UnFreeze in Salesforce using Script

User Freeze/Unfreeze information captured in the UserLogin Object.

User Freeze/Unfreeze is possible in two ways:

  1. Using DataLoader
  2. Execute scripts in Developer console -> Execute Anonymous Window

1. DataLoader

  • Run an Export using DataLoader from the UserLogin object (Note: tick the “Show all Salesforce objects” checkbox)
  • Select the Id, UserId, IsFrozen fields
  • Edit the csv file and change the IsFrozen field to TRUE for any users you want to Freeze or FALSE to unfreeze.
  • Run an Update using DataLoader on the UserLogin object and use the updated csv file you created above.

For More Information: https://help.salesforce.com/articleView?id=000187696&language=en_US&type=1

2. Scripts

#########################User-Freeze##############################
//Internal users – Freeze
List<UserLogin> listInternalUserFreeze = [select id, isfrozen, userid from UserLogin where userid in (select id from user where profile.name in (‘System Administrator’, ‘Sales Rep’) and isactive=true)];
if(listInternalUserFreeze != null && !listInternalUserFreeze.isEmpty()) {
for(UserLogin u : listInternalUserFreeze) {
u.isfrozen = true;
}
update listInternalUserFreeze;
}

//partner users – Freeze
List<UserLogin> listPartnerUserFreeze = [select id, isfrozen, userid from UserLogin where userid in (select id from user where profile.name in (‘Partner’) and isactive=true)];
if(listPartnerUserFreeze != null && !listPartnerUserFreeze.isEmpty()) {
for(UserLogin u : listPartnerUserFreeze) {
u.isfrozen = true;
}
update listPartnerUserFreeze;
}

#######################################################User-Unfreeze###########################
//Internal users – Unfreeze
List<UserLogin> listInternalUserFreeze = [select id, isfrozen, userid from UserLogin where userid in (select id from user where profile.name in (‘System Administrator’, ‘Sales Rep’) and isactive=true)];
if(listInternalUserFreeze != null && !listInternalUserFreeze.isEmpty()) {
for(UserLogin u : listInternalUserFreeze) {
u.isfrozen = false;
}
update listInternalUserFreeze;
}

//partner users – Unfreeze
List<UserLogin> listPartnerUserFreeze = [select id, isfrozen, userid from UserLogin where userid in (select id from user where profile.name in (‘Partner’) and isactive=true)];
if(listPartnerUserFreeze != null && !listPartnerUserFreeze.isEmpty()) {
for(UserLogin u : listPartnerUserFreeze) {
u.isfrozen = false;
}
update listPartnerUserFreeze;
}

To check user freeze/unfreeze in the user detail page of salesforce:

 

Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 13x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply