Try Serpent Free

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 execution

What 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.

Diagnosis

Common causes

Test or seed users were created without a manager
Fixture User records were inserted for testing without populating the Manager field the approval process needs.
Manager field was set after dependent automation already ran
A migration script updated a user's Manager field in a later step than the process that needed it during setup.
Approval process reaches a user with no manager in the chain
A "route up the management chain" approval step hits a top-level or newly created user whose Manager field is blank.

The fix

  1. Populate the Manager field for every relevant user
    Ensure 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;
  2. Sequence user setup ahead of hierarchy-dependent automation
    Assign managers as an earlier step, before any approval process or trigger that depends on the hierarchy fires.
  3. Add a fallback approver for top-of-hierarchy users
    Configure the approval process with a default approver so users with no manager still route somewhere.
In practice

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.

Metadata and data in one deployment flow in Serpent

Prevention

Build a shared test-user factory that always sets a manager chain
Centralize test User creation in one @TestSetup-friendly utility that assigns a manager by default, so every new test inherits a valid hierarchy.
Add Territory Management-style features to scratch org definitions when needed
Where approval processes depend on role hierarchy, seed at least a two-level user hierarchy into scratch org setup scripts, not just the default admin user.
Configure every manager-based approval step with a fallback approver
Treat a missing fallback approver as a design gap in the approval process itself, catching new hires or top-level users before they hit a dead end.
Common questions

MANAGER_NOT_DEFINED, answered

Does every approval process need a manager-based step to hit this error?
Only ones explicitly configured to route based on the submitter's manager or role hierarchy; approval processes with fixed or queue-based approvers aren't affected.
Can a user be their own manager to work around this?
Salesforce blocks a user from being set as their own direct manager, so this isn't a valid workaround; use a real second user or a default approver configuration instead.
Does this apply to Flow-based approvals as well as classic Approval Processes?
Yes. Any automation that resolves "submitter's manager" dynamically, whether a classic Approval Process step or a Flow using the Get Records/Manager lookup pattern, hits the same underlying gap when the field is blank.

Start free. No credit card, no install, no commitment.

Set up in under 15 minutes. No DevOps hire needed.

Curious about faster shipping before you dive in? Let's talk

Commitment free!