How to fix MANAGER_NOT_DEFINED in Salesforce deployments
An approval process or hierarchy-dependent automation fails because the user's Manager field isn't populated.
Surfaces during: runtime approval submission, most often inside Apex test executionWhat it means
MANAGER_NOT_DEFINED fires when an operation that depends on the User role or management hierarchy, most commonly an approval process step configured to route to a user's manager, reaches a User record with no value in the Manager field. Salesforce can't route the approval, or complete whatever hierarchy-dependent logic triggered it, without that chain in place.
Scratch orgs and fresh sandboxes routinely create their default admin user with no Manager set, which is exactly why this error shows up disproportionately in CI test runs rather than in a mature production org where the hierarchy has been filled in over time.
Common causes
The fix
- Populate the Manager field for every relevant userEnsure test and seed User records used in approval or hierarchy-dependent flows have a Manager assigned.
User approver = new User(/* ... */); insert approver; User submitter = new User(ManagerId = approver.Id, /* ... */); insert submitter; - Sequence user setup ahead of hierarchy-dependent automationAssign managers as an earlier step, before any approval process or trigger that depends on the hierarchy fires.
- Add a fallback approver for top-of-hierarchy usersConfigure the approval process with a default approver so users with no manager still route somewhere.
How Serpent prevents this
Serpent's task setup can seed test users with a full hierarchy, so approval-process tests that depend on a manager chain don't fail for a reason unrelated to the code being tested. See the Salesforce deployment error library.

Prevention
Related errors
MANAGER_NOT_DEFINED, answered
Start free. No credit card, no install, no commitment.
Set up in under 15 minutes. No DevOps hire needed.
