What is a Hierarchical relationship and what unique object limitation does it possess in Salesforce?
Answer
Basics: When you create a relationship field on the User object, the type list includes Hierarchical. It links a user to another user, forming a tree. The standard Manager field is the built-in example. You can add custom ones, such as "Dotted-Line Manager" or "Mentor".
How it works:
- Setup > Object Manager > User > Fields & Relationships > New.
- Choose Hierarchical Relationship (it appears only for User).
- Name it and set field-level security.
- Populate it on user records (or via Data Loader).
- Use it in automation: approval processes ("Use the Manager field"), flows (
$Record.Manager.Email), formulas and Apex.
Advanced / deep dive: Hierarchical differs from a normal self-lookup: on other objects you can create a lookup to the same object (for example Account.ParentId is a standard self-lookup, and a custom object can look up to itself), but the special hierarchical type exists only for User. It does not give record access. Access in Salesforce is governed by Role Hierarchy (a separate tree defining data visibility) and the sharing model, not by the Manager field, although manager groups used in sharing and "Grant access using hierarchies" interplay with roles rather than the Manager field. Do not confuse the Role hierarchy with the user hierarchy. Account hierarchy views and Parent Account use a normal lookup. For querying, a user's manager chain can be walked in SOQL with relationship traversal, limited to five levels up (Manager.Manager.Manager.Manager.Manager.Name).
Code / config example:
Approval process step: Next Approver Determined By = "Manager field"
Flow formula: {!$Record.Owner:User.Manager.Email}
SOQL: SELECT Name, Manager.Name, Manager.Manager.Name FROM User WHERE IsActive = true