Month End Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: simple70

Salesforce Certified Platform Developer II ( Plat-Dev-301 ) PDII Question # 12 Topic 2 Discussion

Salesforce Certified Platform Developer II ( Plat-Dev-301 ) PDII Question # 12 Topic 2 Discussion

PDII Exam Topic 2 Question 12 Discussion:
Question #: 12
Topic #: 2

Consider the following code snippet:

Java

01 public with sharing class AccountsController{

03 @AuraEnabled

04 public List getAllAccounts(){

05 return [Select Id, Name, Industry FROM Account];

06 }

08 }

As part of the deployment cycle, a developer creates the following test class:

Java

@isTest

private class AccountsController_Test{

@TestSetup

private static void makeData(){

User user1 = [Select Id FROM User WHERE Profile.Name = 'System Administrator' ... LIMIT 1];

User user2 = [Select Id FROM User WHERE Profile.Name = 'Standard User' ... LIMIT 1];

TestUtils.insertAccounts(10,user1.Id);

TestUtils.insertAccounts(20,user2.Id);

}

@isTest

private static void testGetAllAccounts(){

// Query the Standard User into memory

List result = AccountsController.getAllAccounts();

System.assertEquals(20,result.size());

}

}

When the test class runs, the assertion fails. Which change should the developer implement in the Apex test method to ensure the test method executes successfully?


A.

Add @IsTest(seeAllData=true) to line 12 and enclose lines 15 and 16 within Test.startTest() and Test.stopTest().


B.

Add System.runAs(User) to line 14 and enclose line 15 within Test.startTest() and Test.stopTest().


C.

Query the Standard User into memory and enclose lines 15 and 16 within the System.runAs(user) method.


D.

Query the Administrator user into memory and enclose lines 15 and 16 within the System.runAs(user) method.


Get Premium PDII Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.