Last active
June 28, 2019 09:36
-
-
Save Katulka/d17d3373a0b27ff57bc73685a274f5ca to your computer and use it in GitHub Desktop.
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
set<id> proSet = new set<Id>(); | |
for (Profile p : pro) { | |
system.debug('Non admin: ' + p.Name); // double check | |
proSet.add(p.Id); | |
} | |
// are there any users that are already frozen? That should stay frozen? Use system debug to verify and fix them afterwards. | |
list<UserLogin> realFrozenUsers = [SELECT Id, UserId, isFrozen FROM UserLogin WHERE isFrozen = true AND UserID IN (SELECT id FROM User WHERE isActive = true AND ProfileId IN :proSet)]; | |
String debugMsg = '***STORE/COPY THIS: List of frozen user ids: '; | |
for(UserLogin ul : realFrozenUsers){ | |
debugMsg += '\'' + ul.UserId + '\', '; | |
} | |
system.debug(debugMsg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment