Skip to content

Instantly share code, notes, and snippets.

@zerkz zerkz/scrub_user_data.cls Secret
Last active Jun 1, 2018

Embed
What would you like to do?
User data scrubbing SFDC
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
You can’t perform that action at this time.