For some reason, am I seeing territory data (Territory2Model, Territory2) in my tests, but I have not set SeeAllData=True and I've even set SeeAllData=False.

Without perform any test setup and inserting any data, if I run this:

List<Territory2Model> models = [select Id, Name from Territory2Model];

... I can see the territory model in my org.

Is org Territory data automatically included in tests and you cannot turn it off?


While the documentation doesn't explicitly call it out, the documentation does say:

Starting with Apex code saved using Salesforce API version 24.0 and later, test methods don’t have access by default to pre-existing data in the organization, such as standard objects, custom objects, and custom settings data, and can only access data that they create. However, objects that are used to manage your organization or metadata objects can still be accessed in your tests such as:

  • User
  • Profile
  • Organization
  • AsyncApexJob
  • CronTrigger
  • RecordType
  • ApexClass
  • ApexTrigger
  • ApexComponent
  • ApexPage

Note that the list is not exhaustive, hence the usage of such as. Generally speaking, you can access any object that is normally only edited through the Setup menu or Metadata API.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.