What does INVALID_CROSS_REFERENCE_KEY mean?
Something in your deploy refers to a record by ID, and Salesforce cannot turn that reference into a real record. The message does not say which one.
Most missing-item errors say no X named Y found. This one names nothing, which is why it eats an afternoon.
What causes it?
- A custom app that refers to profiles created in the same deploy. Salesforce saves the custom application before profiles. If the app has
ProfileActionOverrideentries for profiles that are new in this package, those profiles have no ID yet, the reference resolves to nothing, and the app fails (Gearset docs). - A record type the running user cannot use. The data variant reads
Record Type ID value isn't valid for User. The profile of the user who loads the data does not have that record type enabled. The accepted answer on Stack Exchange is to give that profile the record type (Salesforce Stack Exchange). - A stale or wrong-org ID. Record IDs differ between orgs. If a flow, a data file or a custom setting carries a hard-coded sandbox ID, production cannot resolve it.
How do I fix it in Setup?
For the custom app case, which is the common metadata one:
- Open the failed row in Setup > Deployment Status > View Details and find the app named in the line.
- Create the profiles the app refers to in the target before you deploy the app. Or add the Profile type to the package, with those profiles selected, so they travel with the app.
- If it still fails, take the app out of this deploy, create it by hand in the target, and deploy everything else. Gearset lists both options.
- Validate again.
For the record type case:
- In the target, open Setup, Profiles, pick the profile of the user who runs the load, and open the object's record type settings.
- Enable the record type, or run the load as a user whose profile has it.
How do I fix it with the CLI?
Check the exact failing file first, because the error line gives the component:
sf project deploy start --source-dir force-app --dry-run --test-level NoTestRun -o target-org --json
Read details.componentFailures in the output, not only the top-level message.
How do I avoid it?
Deploy in order: profiles and permission sets before the apps that use them. Do not copy record IDs between orgs. Look them up by name in the target. The profiles vs permission sets guide explains why we keep access in permission sets, and the profile glossary entry defines the pieces. If your deploys keep hitting order problems, AI Salesforce deployments checks deploy order before a bundle ships.
Questions about INVALID_CROSS_REFERENCE_KEY
Why does the error not tell me which ID is wrong?
The message only says the reference could not be resolved. Use the component name on the failed row to find the file, then look for profile, record type or user references inside it.
Is invalid cross reference id the same as INVALID_CROSS_REFERENCE_KEY?
Yes. Deploys show the lower-case phrase. The API and data loads show the code, often with the record type ID.
Does it happen with connected apps?
Yes. A Stack Exchange question reports it when pushing a connected app with the CLI. Check which profiles or permission sets the app refers to.
Will a retry fix it?
Not by itself. The order of saves is what failed, so deploy the referenced items first.