We've delegated User creation and Administration to helpdesk staff, but the delegated Admins cannot populate the Manager field because only someone with edit all data can populate that field. Is it possible to create a trigger that looks at a new custom field that the delegated Admin populates with the Manager, then when it's saved the standard Manager field is populated from that field?
1 Answer
Yes, you can create a User to User lookup field (hierarchy) on the User object, for instance "Custom_Manager__c," and use the following logic. Apex, by default, plays in system mode.
trigger setManagerFromCustomField on User (before insert, before update) {
for (User u : Trigger.new) {
if (u.Custom_Manager__c != null) {
u.ManagerId = u.Custom_Manager__c;
}
}
}