Platform
INVALID_CROSS_REFERENCE_KEY: find the unusable Salesforce ID
Check org, object type, record existence and relationship eligibility before retrying an import with an invalid reference.
A Salesforce-shaped ID is not proof that the destination can use it. The record may belong to another org or be invalid for that field.
Start with the failed row and its reference fields rather than retrying the entire import. Salesforce’s invalid-ID guidance covers errors caused by incorrect or unusable identifiers during data operations.
Validate the destination, object and record
Confirm the target org first. Sandbox and production mappings must be kept separate, even when record names match. Then check that the ID refers to the object type allowed by the relationship.
Inspect whether the record still exists and is eligible for the operation. An owner reference, record type or parent relationship can have requirements beyond syntactically valid ID text. The executing user’s access also matters; don’t treat this code and an insufficient-access code as perfectly exclusive diagnoses.
Capture which field failed when the API supplies it. If the response doesn’t identify the field, reproduce with a minimal set of intended changes in a non-production environment. Add the references back deliberately until the failing condition is understood.
Replace hardcoded IDs with explicit mapping
Store stable business identifiers in the source system and resolve them to destination records. For a migration, produce a mapping file from successfully created target records before loading dependent records.
Check the mapping for missing and ambiguous matches. Selecting the first record with the same display name can attach data to the wrong parent while producing no error at all.
Record types need their own resolution strategy. Prefer metadata-aware lookup appropriate to the destination and validate availability for the caller. A record type ID copied from a development org is not a portable configuration value.
Retry only after correcting the cause
A bad reference generally won’t become valid because the same request is sent again. Put the record into a repair queue with its source identifier, destination object and failed reference category. Avoid logging credentials or unrestricted payloads.
For partial-success imports, retain the result associated with each input row. Salesforce’s database error handling provides the model for checking individual outcomes in Apex. Retrying already successful inserts can create duplicates unless the operation uses an appropriate idempotent key.
Test wrong-org IDs, wrong-object IDs, deleted parents, unavailable record types and the valid mapping. Include the intended integration user in acceptance testing.
The fix is complete when the mapping process prevents the same invalid reference from being generated again. Repairing one CSV cell helps today’s load; validating destination references helps the next one.