2

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?

4
  • If I follow you .... 1) Product2 data is copied from PROD to sandbox as expected; lookup fields by definition will have 'ghost ids" as those values are copied from PROD during sandbox creation; 2) When you run tests w/o SeeAllData and those tests invoke workflows, you are fetching from /interacting with the org's Product2 records rather than from the mocked Product2 and custom family object?
    – cropredy
    Oct 10 '18 at 22:16
  • @cropredy precisely! I spun up 4 sandboxes to demonstrate this to SF Support. I hope to have another call with them soon. Oct 11 '18 at 1:24
  • Did you ever figure out that issue? Looks like there might some bugs around data isolation and the Product2 objects? I've had an issue here with data isolation and Product2 around the Product SKU field salesforce.stackexchange.com/questions/290542/…
    – jeromegv
    Jan 8 '20 at 21:26
  • I never did get to the bottom of this @jeromegv . The workaround I came up with was a little script that found all of those records with the "ghost ids" and cleared the field values. Jan 8 '20 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.