[SalesForce] In test class can see all org users in list

I have written one query in test class for fetching users,as per my understanding query should return the user records created in test class only,but its giving all user from salesforce org.is that correct.SeeAlldata is false
list<user>userList=[select id from user];

giving all records from org

Best Answer

This is the expected behavior and is documented in the Isolation of Test Data from Organization Data in Unit Tests (emphasis mine):

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
Related Topic