Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce DEX-450 Exam - Topic 2 Question 112 Discussion

Posted by Justine on Apr 06, 2025 at 10:06 PM

Consider the following code snippet:

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

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?

Suggested Answer: D

Get Premium DEX-450 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
36 comments · newest first
NI
Nidia 11 months ago
I’ve seen C work in similar cases, might be worth a try.
GO
Goldie 11 months ago
Wait, can you really use @IsTest(SeeAllData=true)? That feels risky!
JA
James 11 months ago
I disagree, A seems more appropriate for admin context.
FA
Fallon 11 months ago
D looks complicated, not sure if it’s necessary.
FE
Felicidad 11 months ago
I think option B is the way to go. Standard User should work.
GA
Gayla 12 months ago
I feel like option A could work since it involves querying the Administrator, but I can't recall if that's the best practice for this scenario.
FR
Francisca 12 months ago
I think I saw something about `@isTest(seeAllData=true)` in our study materials, but I'm not confident if that's the right approach here.
SU
Suzi 1 year ago
This question feels similar to one we practiced where we had to adjust test methods for user contexts. I think option B might be the right choice.
KE
Kenny 1 year ago
I remember something about using `System.runAs` to test different user permissions, but I'm not sure which user to query.
ED
Edwin 1 year ago
This seems straightforward. The developer just needs to enclose the relevant lines within the `System.runAs()` method, using the appropriate user. I'm confident I can solve this one.
JU
Juliann 1 year ago
Okay, I think I've got a strategy here. The issue is likely related to the user context, so I'll need to look into using the `System.runAs()` method to ensure the test runs as the correct user.
LO
Louvenia 1 year ago
I'm a bit confused by the question. The test class seems to be failing, but I'm not sure what the issue is. I'll need to review the code more closely.
BO
Bobbie 1 year ago
Hmm, this looks like a tricky one. I'll need to carefully analyze the code and test class to figure out the best approach.
OL
Oliva 2 years ago
Option A seems a bit excessive, querying the Admin user just to run a simple test? I'd stick with the Standard User approach in option B.
AU
Audra 1 year ago
↳ replying to Oliva
I think sticking with the Standard User in option B is the way to go.
DA
Dalene 1 year ago
↳ replying to Oliva
Yeah, querying the Admin user for a simple test does seem unnecessary.
MA
Margurite 1 year ago
↳ replying to Oliva
I agree, option B seems like the most straightforward approach.
CY
Cyndy 2 years ago
Hmm, this is a tricky one. I'm torn between B and D, but I think I'll go with D. Might as well go all-in with the system calls and test wrappers.
TE
Teddy 1 year ago
↳ replying to Cyndy
User2
AN
Annelle 1 year ago
↳ replying to Cyndy
User1
AR
Aretha 2 years ago
I'm going to have to go with option D on this one. Enclosing the code within the System.runAs() and Test.start/stopTest() methods seems like the most straightforward approach.
CA
Cathrine 2 years ago
But option D doesn't seem to address the issue with the assertion failure.
AM
Amie 2 years ago
I disagree, I believe the correct answer is D.
CA
Cathrine 2 years ago
I think the correct answer is A.
RO
Ronnie 2 years ago
Option C looks interesting with the @IsTest(seeAllData=true) annotation. That might be the easiest solution to bypass any permission issues.
ME
Mee 1 year ago
↳ replying to Ronnie
Yeah, I agree. That annotation should help with any permission problems during testing.
AI
Aimee 1 year ago
↳ replying to Ronnie
I think option C is the best choice. It includes the @IsTest(seeAllData=true) annotation.
JO
Jody 2 years ago
The code seems to be dealing with permissions, so I think option B is the way to go. Querying the Standard User and running the test as that user should ensure the test passes.
RO
Rosamond 1 year ago
↳ replying to Jody
Let's go with option B then. Querying the Standard User seems like the most logical solution.
MA
Marguerita 1 year ago
↳ replying to Jody
I'm not sure about option A. I still believe option B is the best approach for this scenario.
HA
Hayley 1 year ago
↳ replying to Jody
But what about option A? Querying the Administrator user and using the system.runAs method could also work.
JA
Javier 1 year ago
↳ replying to Jody
I think option B is the correct choice. Running the test as the Standard User should solve the issue.
NI
Nina 1 year ago
↳ replying to Jody
True, enclosing lines 15 and 16 within Test.startTest() and Test.stopTest() is crucial for successful execution.
SV
Svetlana 2 years ago
↳ replying to Jody
I'm not sure about that. Maybe adding System.runAs(User) on line 14 could be the key.
AL
Alayna 2 years ago
↳ replying to Jody
But what about adding @Istest(seeAllData=true) to line 12? That could also solve the issue.
BO
Bong 2 years ago
↳ replying to Jody
I think option B is correct. Querying the Standard User should help with permissions.
0/2000 characters

Save Cancel