Salesforce Certified Platform Developer 1 (SP25) CRT-450 Question # 24 Topic 3 Discussion

Salesforce Certified Platform Developer 1 (SP25) CRT-450 Question # 24 Topic 3 Discussion

CRT-450 Exam Topic 3 Question 24 Discussion:
Question #: 24
Topic #: 3

Consider the following code snippet:

apex

CopyEdit

public class with sharing AccountsController {

@AuraEnabled

public List getAllAccounts(){

return [SELECT Id, Name, Industry FROM Account];

}

}

Apex Test Class Snippet:

apex

CopyEdit

@isTest

private class with sharing AccountsController_Test {

@testSetup

private static void makeData(){

User user1 = [SELECT Id FROM User WHERE Profile.Name = 'System Administrator' AND isActive = true LIMIT 1];

User user2 = [SELECT Id FROM User WHERE Profile.Name = 'Standard User' AND UserName = 'test@test.com' AND isActive = true LIMIT 1];

TestUtils.insertAccounts(10, user1.Id);

TestUtils.insertAccounts(20, user2.Id);

}

@isTest

private static void getAllAccounts_StandardUser_Test(){

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.

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


B.

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


C.

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


D.

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


Get Premium CRT-450 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.