I have an interesting situation, and I am working a Case with SF Support on. I though I would ask the same question here and see if anyone else has seen something similar.
It starts with a Custom Lookup field on the Product2 sObject, that looks up to a "Product Family" sObject. I also have a workflow rule that evaluates
Asset.Product2.Product_Family__c. This works fine in Production whether the Asset's Product2 has a lookup value to Product Family or not. Happy times.
SO... now we create a new developer sandbox. That comes with all the Product2 records but no Assets and no Product Families. No sweat, we simply create those records in our test Classes as per best practice around isolating test data. We are using Product2 Product Codes and Names that match our Production records, but it's isolated test data, so no problems there, right?
When we look in the sandbox at a Product2 record, what we see for the lookup value is something that looks like a record Id... sort of a "ghost" of the original lookup value. Hover over that "ghost" in the UI and there's a tool tip that indicates that the record has been deleted.
Running a test Class we get a failure like this..
System.DmlException: Upsert failed. First exception on row 1; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, The formula in the "Asset Updated" rule or process is invalid due to the following:
The data you were trying to access could not be found. It may be due to another user deleting the data or a system error...
We get this error even if we very carefully craft the test data to have all the references that we would expect in a Production environment.
Here's the weird part. If we go into the sandbox and delete all of those lookup value "ghosts", the test run just fine.
To put that another way, I have to alter Org data to get a test method to run correctly even though the that test method is using isolated test data. It seems like I can't isolate my Org data from workflow rules that run in a test context.
Has anyone else seen anything similar to this? Is Org data visible to workflow rules when running in a test context?