Salesforce Certified Platform Developer free question 9 / 10 · Domain 4: Testing, Debugging, and Deployment
An org has three Account records named Acme and several active users. The following test class is run, with no SeeAllData setting on the class or the method. @IsTest private class IsolationTest { @IsTest static void run() { Integer accts = [SELECT COUNT() FROM Account WHERE Name = 'Acme']; Integer users = [SELECT COUNT() FROM User WHERE IsActive = true]; System.debug(accts + ' / ' + (users > 0)); } } Which output appears in the debug log, according to the Apex Developer Guide?
- 0 / false
- 3 / true
- 0 / true
- 3 / false
Show the answer and explanation
Answer: C
Why this is correct
"Isolation of Test Data from Organization Data in Unit Tests" says test methods by default cannot access pre-existing org data such as standard objects, custom objects, and custom settings, and see only the data they create themselves. The exceptions are objects used to manage your org or metadata objects, and its examples include User, Profile, Organization, and RecordType. So the count of Acme accounts is 0, and active users can be queried, giving true.
Why the other options are wrong
"3 / true" … By default a test cannot see the org's existing records. The three Acme accounts were not created by the test, so the count is 0. They would be visible only with @IsTest(SeeAllData=true).
"0 / false" … User is on the list of objects that are exceptions to the isolation, so it can be queried without a SeeAllData setting. With active users in the org the count is above zero, so the second value is true.
"3 / false" … Isolation applies to business data such as accounts, while User is on the exception side. The pairing here is reversed.
Worth remembering
The isolation applies to all code that runs in the test context. A trigger started by the test also cannot see org data that the test cannot see.