INVALID_CROSS_REFERENCE_KEY

The record references an ID that does not exist or is not valid for that field.

Common causes

  • An ID was hardcoded from another org. Record IDs differ between sandbox and production.
  • The record type ID does not belong to the object, or is not assigned to the user’s profile.
  • The owner is a queue that does not support the object.
  • The referenced record was deleted.
  • An opportunity product references a price book entry from a different price book.

How to fix

  • Query the ID in the target org to confirm it exists and is the right object type.
  • Replace hardcoded IDs with lookups by name:
Id rtId = Schema.SObjectType.Account
    .getRecordTypeInfosByDeveloperName()
    .get('Business_Account')
    .getRecordTypeId();
  • Assign the record type to the user’s profile or permission set.
  • Add the object to the queue’s supported objects.

You may also like...