-
-
Save zerkz/3d6c54be0b943ddd50fbb142c5425ddc to your computer and use it in GitHub Desktop.
User data scrubbing SFDC
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
public static String generateRandomString(Integer len) { | |
final String chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; | |
String randStr = ''; | |
while (randStr.length() < len) { | |
Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length()); | |
randStr += chars.substring(idx, idx+1); | |
} | |
return randStr; | |
} | |
List<String> doNotEditIds = new List<String>{ '005U0000003TZ49', '0050B0000080YI2QAM', '0050B000007zsmKQAQ', '0050B000007zsmLQAQ'}; | |
Set<String> unableToDeactivateIds = new Set<String> {'0050B000007C3ZwQAK', '0050B000007zsmKQAQ', '005U0000005sd5PIAQ','0050B000006qMw2QAE','005U0000003FOvxIAG','0050B0000080e7ZQAQ', '005U0000004PBGOIA4', '0050B000006qCyN', '0050B0000080Dpy', '005U0000006FECa'}; | |
List<User> allUsers; | |
allUsers = [SELECT Id, isActive from User where Id NOT IN :doNotEditIds and UserType != 'AutomatedProcess' AND Phone != 'FIXED' limit 148]; | |
System.Debug(allUsers.size()); | |
for(User u: allUsers) | |
{ | |
String garbageEmail = 'interview=' + generateRandomString(10) + '@interview.com'; | |
u.FirstName = generateRandomString(5); | |
u.LastName = generateRandomString(5); | |
u.PostalCode = ''; | |
u.UserName = garbageEmail; | |
u.Email = garbageEmail; | |
u.MobilePhone = ''; | |
u.Phone = 'FIXED'; | |
if(!unableToDeactivateIds.contains(u.Id)) { | |
u.IsActive = false; | |
} | |
try { | |
update u; | |
} catch (Exception e) { | |
System.Debug(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment