Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

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 modesystem 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;
        }
    }
}

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;
        }
    }
}

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;
        }
    }
}
Source Link
Brian Mansfield
  • 6.4k
  • 5
  • 37
  • 69

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;
        }
    }
}