Skip to content

Instantly share code, notes, and snippets.

@Katulka
Katulka / Salesforce Freeze Users - Script 2
Last active December 1, 2016 20:51
Using Execute Anonymous to freeze/unfreeze in bulk: We found this to be more straightforward for developers, and control feels more granular/confident. TIP: Do this in a sandbox before trying in your production environment. Script 1 will gather any existing frozen users so you don’t accidentally “Unfreeze” them in the last step. Script 2 does th…
// Script #2 (modify and repeat)
// script for FREEZING/UNFREEZING users in order to perform administrative tasks
// CONTINUE to run this script over and over depending on how many users are in the org (see batch size below)
// Review the DML rows portion of the debug log, run until that says 0
// TODO ----------------------------------------------------------------------------------------------------------------------------
// size of query for userslogin records and DML
Integer batchSize = 2000;
//TIP: Set batchSize to 0 and run this to review the debugs, verifying profile name etc.
@Katulka
Katulka / Salesforce Freeze Users - Script 1
Last active June 28, 2019 09:36
Using Execute Anonymous to freeze/unfreeze in bulk: We found this to be more straightforward for developers, and control feels more granular/confident. TIP: Do this in a sandbox before trying in your production environment. Script 1 will gather any existing frozen users so you don’t accidentally “Unfreeze” them in the last step. Script 2 does th…
// Script #1
// Script to run FIRST before Freezing the users
// get sys-admin profiles for exclusion - ENTER ANY CUSTOM PROFILES FOR SYSTEM ADMINISTRATORS
list<Profile> admins = [SELECT id FROM Profile WHERE Name IN ('System Administrator', 'Premier Support User')];
// get profiles to be included
list<Profile> pro = [SELECT id, Name FROM Profile WHERE id Not IN :admins ORDER BY Name];
// add to set