Data.com: How to unit test with DandBCompany data?

In an org with Data.com Premium Clean enabled, I have code that refers to the DandBCompany object to lookup relationships (via DandBCompany.DomesticUltimateDunsNumber). How do I write unit tests for this logic? DandBCompany is read-only, so how do I populate it with test data?

Answer

Some Objects can’t be created in unit tests and you need to use the @isTest(seeAllData=true) annotation to access org data.

In Isolation of Test Data docs Salesforce touches on this with:

There might be some cases where you can’t create certain types of data from your test method because of specific limitations.

I have had to use the @isTest(seeAllData=true) annotation in the past to deal with those situations. I don’t see how you can avoid it. You can’t create the needed record with data in your unit test.

Attribution
Source : Link , Question Author : Jason Clark , Answer Author : Peter Knolle

Leave a Comment