INVALID_CROSS_REFERENCE_KEY: meaning and how to fix it

Data and DML Checked against the official docs on Source: SOAP API Developer Guide: Core Data Types, StatusCode

Quick answer

INVALID_CROSS_REFERENCE_KEY: An ID in a lookup or master-detail field does not point to a usable record: it does not exist in this org, belongs to the wrong object, was deleted, or came from another org (for example a production ID used in a sandbox). Start with: Check that the ID exists in this org with a SOQL query on the target object.

Typical message: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id

Cause

An ID in a lookup or master-detail field does not point to a usable record: it does not exist in this org, belongs to the wrong object, was deleted, or came from another org (for example a production ID used in a sandbox).

How to fix INVALID_CROSS_REFERENCE_KEY

  1. Check that the ID exists in this org with a SOQL query on the target object.
  2. Check the ID prefix matches the object the lookup expects.
  3. After a data migration or sandbox refresh, remap IDs instead of copying them.

Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.

Frequently asked questions

What does INVALID_CROSS_REFERENCE_KEY mean in Salesforce?

An ID in a lookup or master-detail field does not point to a usable record: it does not exist in this org, belongs to the wrong object, was deleted, or came from another org (for example a production ID used in a sandbox).

How do I fix INVALID_CROSS_REFERENCE_KEY?

1. Check that the ID exists in this org with a SOQL query on the target object. 2. Check the ID prefix matches the object the lookup expects. 3. After a data migration or sandbox refresh, remap IDs instead of copying them.

More Data and DML errors

SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.