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

  • yes all users from your org, but it's not recommended way to use SeeAlldata
    – sdandamud1
    Commented Oct 24, 2019 at 20:21
  • 1
    My @SeeAllData is not true ....still its giving all users from org.. Commented Oct 24, 2019 at 20:23
  • the reason is objects which managing org and metadata can access in test class,such as User,Profile ..etc Commented Oct 24, 2019 at 20:24

1 Answer 1


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .