You need to sign in to do that
Don't have an account?
LinThaw
SeeAllData on User Object
Hi there,
I am trying following test class with api version 46.
my expected result is as follow.
totalUser = 0 and totalAccount = 0
But totalUser is not 0.
Any suggestion for using with @isTest(SeeAllData = false) User Object?
Thanks
Regards,
LinThaw
I am trying following test class with api version 46.
my expected result is as follow.
totalUser = 0 and totalAccount = 0
But totalUser is not 0.
Any suggestion for using with @isTest(SeeAllData = false) User Object?
@isTest(SeeAllData = false) public class TestClassSample { private static testMethod void test01() { Test.startTest(); System.debug('Total User Record = ' + [Select Count(Id) totalUser From User]); Test.stopTest(); } private static testMethod void test02() { Test.startTest(); System.debug('Total Account Record = ' + [Select Count(Id) totalAccount From Account]); Test.stopTest(); } }
Thanks
Regards,
LinThaw
Unfortunately, users are not affected by @isTest(SeeAllData=false). See below link for additional information on which objects are supported and which not.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data_access.htm
Regards,
MKR
If you want to access org's original user data, in order to do that you have to make @isTest(SeeAllData = true).
But, it will applied to all methods in test class. You apply this on specific methods as well as shown below:- In the above code the debug will be
totalUser = total user in your org
totalAccount = 0
You can always anyway create users for your tests and use that data to ensure that the user is always in a shape that you want. These users are automatically removed when the test execution ends (like any other data created in test context).
Regards,
MKR
You can create a test user in your test class.
Please follow the below code:
Thanks