Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I want to create a User in test class with a System Administrator profile.

The issue which I have is that I have seeAllData = false wherein the test class would only use data from within the test class.

 List<Profile> ps = [select id, name from Profile where  name = 'System Administrator'];

This might not return any values.

Any ideas about how we can create a user

I can get the data for the query on even with seeAllData= false. So is it that Profile records are visible even if SeeAllData = false?

1 Answer

0 votes
by (32.1k points)
edited by

So, the user profiles and objects are actually considered "objects which are used to manage your organization" and they can be accessed without any bad consequences of whether or not your test class/method includes the IsTest(SeeAllData=true)  annotation

Objects which are accessible in this manner include:

  • RecordType
  • ApexTrigger
  • Organization
  • ApexComponent
  • ApexClass
  • ApexPage

Become a certified Salesforce professional by going for Intellipaat’s Salesforce Certification!

Browse Categories

...