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 Oct 24 '19 at 20:21
  • My @SeeAllData is not true ....still its giving all users from org.. – ajay bagdad Oct 24 '19 at 20:23
  • the reason is objects which managing org and metadata can access in test class,such as User,Profile ..etc – ajay bagdad Oct 24 '19 at 20:24

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
| improve this answer | |

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.