SfSkills Domains Docs GitHub

Home / devops / deployment-error-diagnosis

deployment-error-diagnosis

Pattern catalog of Salesforce metadata-deploy error strings and their fixes: `Cannot change type` of field, dependent-metadata ordering, profile / permission set delta issues, INVALID_CROSS_REFERENCE_KEY, missing-reference errors, inactive-flow and picklist component errors, `entity is in use` on field deletion, package.xml-shape mistakes. NOT for sandbox partial deploys, rollbackOnError, or testLevel coverage models — use devops/deployment-error-troubleshooting. NOT for change set orchestration — use devops/change-set-deployment.

Open the skill folder on GitHub


Deployment Error Diagnosis

Salesforce deploy errors are notorious for being technically correct but actionably opaque. "INVALID_CROSS_REFERENCE_KEY" tells you a reference is broken, not which one. "Field type cannot be changed" doesn't tell you which records are using the field. "Dependent class is invalid and needs recompilation" implicates some class but not yours.

This skill is a translation layer: error message → actual cause → actual fix. It assumes you have the deploy log; the input is the error string, the output is the next action.

What this skill is NOT. Pipeline design (CI/CD shape, environment strategy) is devops/sfdx-cicd-pipeline. Change-set construction mechanics — admin/changeset-builder. This skill is for the "my deploy failed; what does this mean" moment.


Before Starting


Core Concepts

The most-common error patterns

Error message (paraphrased)Actual causeFix
Cannot change type of fieldField already populated; type changes restrictedEither: data-clear + change, or new field + migration + delete old
Dependent class is invalid and needs recompilationA class that depends on the changed metadata didn't rebuildAdd the dependent class to the package; deploy together
INVALID_CROSS_REFERENCE_KEY: invalid cross-reference idA profile / permset references metadata not in the targetAdd the referenced metadata; or scrub the profile's reference
Field-level security cannot be set on a non-existent fieldProfile delta references a field the package doesn't deploy and target doesn't haveAdd the field to the package; or remove the FLS line
INVALID_FIELD: No such column (in test class)Schema referenced in test doesn't exist in targetAdd the schema to package, or fix the test
Average test coverage across all Apex Classes is below 75%Org-wide or per-class coverage thresholdAdd tests for the class with low coverage
Cannot deploy a package containing inactive flowFlow with <status>Draft</status>Set <status>Active</status> or Obsolete before deploy
Required field is missing: name (on a record)Standard validation rule on target rejecting Apex test dataUse Test.startTest() + bypass or fix the test data
Component error: 'X' is not a valid value for type 'Y'Picklist value missing in targetAdd picklist value to package; or update package XML to omit
Ambiguous reference to a methodTwo classes have same method signature; deploy order resolves wrong oneFully-qualify the method call or rename
entity is in use (when retiring fields)Active references in flows / formulas / validation rulesFind references; deactivate or delete them; redeploy

package.xml ordering smells

package.xml doesn't have explicit ordering — the platform resolves dependencies. But:

Profile / Permission Set deltas

Profiles and permission sets are notoriously verbose; SFDX often exports them in full (every FLS line for every field). Deploying a full profile against a target with different fields produces errors per missing field.

The cleanest patterns:

Test coverage failures

Salesforce requires 75% test coverage org-wide for production deploy. Per-class coverage is also tracked. Failures present as:

Average test coverage across all Apex Classes is 73%, at least 75% is required.

Or:

Failed: classes/MyHandler — only 60% covered

Diagnosis: query ApexCodeCoverageAggregate to find low-coverage classes; add tests; redeploy.


Common Patterns

Pattern A — Cannot change type field migration

When to use. Need to change Region__c from Text to Picklist.

Sequence.

  1. Create new field Region_v2__c of the new type.
  2. Migrate data: SOQL update setting v2 from v1 mapping rule.
  3. Update all references (Apex, formulas, validation rules,

    reports, dashboards, page layouts) to use v2.

  4. Delete v1 in a separate deploy.

The "delete v1" step requires v1 to have no remaining references — the deploy fails if it does, with a more useful error listing the references.

Pattern B — Profile / permset cross-reference fix

When to use. Error: Cannot find field Account.Custom_X__c referenced in profile.

Diagnosis.

  1. Confirm the field exists in source.
  2. Confirm the package.xml includes the field (either explicitly

    or via <members>*</members> for CustomField).

  3. If yes: target may have a stale profile referencing the field.

    Add the field to the package.

  4. If no: the field needs to be added to the package, OR the

    profile delta needs to omit the FLS line for the missing field.

Pattern C — Test coverage failure on a deploy

When to use. Production deploy fails on coverage threshold.

Diagnosis.

  1. SOQL: [SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate WHERE NumLinesUncovered > 0 ORDER BY NumLinesUncovered DESC LIMIT 20].
  2. The classes with the most uncovered lines are the targets.
  3. Write tests for them in the same package as the deploy.
  4. Re-run.

For "average across all classes" failures, the calculation is total-lines-covered / total-lines. One fully-covered new class can lift the average enough; check a representative high-line-count class first.

Pattern D — Flow active / inactive deploy errors

When to use. "Cannot deploy a package containing inactive flow" or "Active flow refers to inactive subflow".

Approach.

Pattern E — Cleaning up entity is in use for field deletion

When to use. Field deletion blocked by "entity is in use".

Diagnosis.

Approach.

  1. Inventory references; deactivate / replace each.
  2. Deploy the deactivations / replacements as a separate package.
  3. Then deploy the field deletion.

Decision Guidance

Error patternApproach
Cannot change typePattern A (new field + migrate + delete old)
Dependent class is invalidAdd the dependent class to the package; deploy together
INVALID_CROSS_REFERENCE_KEYTrace the broken reference; usually missing metadata in package
Field-level security on non-existent fieldAdd field to package OR scrub profile delta
Average test coverage below 75%Pattern C (find low-coverage class, add tests)
Cannot deploy inactive flowSet <status>Active</status> or <status>Obsolete</status>
entity is in usePattern E (find references, deactivate, redeploy)
Component error: not a valid picklist valueAdd picklist value to package; or align values across orgs
Wildcard + explicit members confusionPick one (wildcard OR explicit, not both)
Ambiguous reference to methodFully-qualify or rename

  1. Capture the full error message + the deploy package contents.
  2. Match against the error patterns above. Most production deploy errors fit a known shape.
  3. For unmatched errors: search the salesforce.stackexchange.com Q&A for the exact error string.
  4. Apply the fix in source control. Don't hotfix the target org directly; the source-target gap creates more errors.
  5. Re-run the deploy.
  6. For deploys that keep failing: capture the sequence of errors. The order tells you the dependency graph.

Review Checklist


Salesforce-Specific Gotchas

  1. Cannot change type requires data clearance. Type changes are restricted on populated fields. (See references/gotchas.md § 1.)
  2. Profile / permset full-export deploys verbose deltas that fail per missing field. (See references/gotchas.md § 2.)
  3. Test coverage org-wide vs per-class — failures can be either; diagnose appropriately. (See references/gotchas.md § 3.)
  4. <members>*</members> + explicit <members> for the same type confuses the platform. (See references/gotchas.md § 4.)
  5. Flow retirement should be Obsolete, not delete. Preserves history; doesn't run new invocations. (See references/gotchas.md § 5.)
  6. entity is in use rarely surfaces every reference. Search source comprehensively, not just Setup → Where Is This Used. (See references/gotchas.md § 6.)
  7. PermissionSetGroup deploys after component PermissionSets. Order matters for groups. (See references/gotchas.md § 7.)

Output Artifacts

ArtifactDescription
Error → Cause → Fix mappingTranslated explanation for the specific error
Updated package.xmlIf the fix is a packaging-level change
Test class additionsIf coverage was the failure
Reference cleanup commitsIf entity is in use was the failure

Package files