Created
March 10, 2015 12:59
-
-
Save omniphx/3ca397e680e0a97679eb to your computer and use it in GitHub Desktop.
Remove User from hierachy fields
This file contains hidden or 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
Id userId = '005i000000XXXXX'; | |
List<String> fields = new List<String>{'Sales_Director__c','Account_Coordinator__c','Account_Services_Representative__c','Program_Director__c','Sales_Director__c','Placement_Manager__c','Inside_Sales_Representative__c','New_Family_Placement_Manager__c'}; | |
User[] users = [ | |
SELECT Id, Name, Account_Coordinator__c, Account_Services_Representative__c,Inside_Sales_Representative__c, New_Family_Placement_Manager__c,Placement_Manager__c, Program_Director__c, Sales_Director__c | |
FROM User | |
WHERE Account_Coordinator__c = :userId | |
OR Account_Services_Representative__c = :userId | |
OR Inside_Sales_Representative__c = :userId | |
OR New_Family_Placement_Manager__c = :userId | |
OR Placement_Manager__c = :userId | |
OR Program_Director__c = :userId | |
OR Sales_Director__c = :userId]; | |
List<User> updateUsersList = new List<User>(); | |
for(User user : users){ | |
if(user.Account_Coordinator__c == userId){ | |
user.Account_Coordinator__c = null; | |
} | |
if(user.Account_Services_Representative__c == userId){ | |
user.Account_Services_Representative__c = null; | |
} | |
if(user.Inside_Sales_Representative__c == userId){ | |
user.Inside_Sales_Representative__c = null; | |
} | |
if(user.New_Family_Placement_Manager__c == userId){ | |
user.New_Family_Placement_Manager__c = null; | |
} | |
if(user.Placement_Manager__c == userId){ | |
user.Placement_Manager__c = null; | |
} | |
if(user.Program_Director__c == userId){ | |
user.Program_Director__c = null; | |
} | |
if(user.Sales_Director__c == userId){ | |
user.Sales_Director__c = null; | |
} | |
//system.debug('user: ' + user.Name); | |
updateUsersList.add(user); | |
} | |
system.debug('updateUsersList: ' + updateUsersList); | |
update updateUsersList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment