function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hanna BergsmaHanna Bergsma 

INVALID_CROSS_REFERENCE_KEY: invalid cross reference id When Deleting Email Records Via Scheduled Flow

I am setting up a scheduled flow that deletes emails older than 3 years old. I have a formula field that calculates age in days that I am using for criteria.

I am gettting "The flow tried to delete these records: null. This error occurred: INVALID_CROSS_REFERENCE_KEY: invalid cross reference id. " but I can see that its grabbing at least one Email Messgae Id in Debug Details. Help!
User-added imageUser-added image
VinayVinay (Salesforce Developers) 
Hi Hanna,

Invalid Cross Reference ID, generally means that the objects you updated have ID fields in them that are filled with IDs that are either invalid or that your user does not have permissions to see.  

Kindly re-check if you have access to object and record id's

Thanks,
Hanna BergsmaHanna Bergsma
Thank you, Vinay. I am a system admi, I double checked the obejcts for full permissions, and I have "Modify all" permissions.

I ran the flow for just one record, instead of a collection, and it gave me the error for an email message that had no parent case. Could it be that orphaned emails that were orignally email-to-case are causing this? Even if the lookup is empty (because the case was deleted for some reason) is it still searching for the deleted case? 

If so, how can I find all emails existed for deleted cases?
VinayVinay (Salesforce Developers) 
At moment,  I can say try debugging flow that should narrow down the issue.

https://help.salesforce.com/articleView?id=flow_test_debug.htm&type=5

Thanks,