Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Certified Platform Developer II All Questions

View all questions & answers for the Certified Platform Developer II exam

Exam Certified Platform Developer II topic 1 question 33 discussion

Actual exam question from Salesforce's Certified Platform Developer II
Question #: 33
Topic #: 1
[All Certified Platform Developer II Questions]

@isTest
static void testIncrement() {
Account acct = new Account(Name = 'Test');
acct.Number_Of_Times_Viewed__c = 0;
insert acct;
AuditUtil.incrementViewed(acct.Id);
Account acctAfter = [SELECT Number_Of_Times_Viewed__c FROM Account WHERE Id = :acct.Id][0]
System.assertEquals(1, acctAfter.Number_Of_Times_Viewed__c);
}
The test method above calls an @future method that increments the Number_of_Times_Viewed__c value. The assertion is failing because the
Number_of_Times_Viewed__c equals 0.
What is the optimal way to fix this?

  • A. Change the initialization to acct.Number_Of_Times_Viewed__c = 1.
  • B. Add Test.startTest() before and Test.stopTest() after AuditUtil.incrementViewed.
  • C. Add Test.startTest() before and Test.stopTest() after insert acct.
  • D. Change the assertion to System.assertEquals(0, acctAfter.Number_Of_Times_Viewed__c).
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Soliton321
Highly Voted 3 years, 10 months ago
B is correct. Check first section in doc https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_dml.htm
upvoted 27 times
...
singhkar
Highly Voted 3 years, 5 months ago
B is the correct ans
upvoted 8 times
...
Jokei
Most Recent 11 months, 3 weeks ago
Selected Answer: B
B is the correct answer. Test.StopTest() allows you to test the results of asynchronous behavior in your code.
upvoted 2 times
...
VVeguru
1 year, 4 months ago
Why A was given in Reveal Answer
upvoted 1 times
...
santo_aj
1 year, 6 months ago
Selected Answer: B
B is the correct answer. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_dml.htm
upvoted 1 times
...
sf2022
1 year, 12 months ago
Selected Answer: B
B is correct
upvoted 2 times
...
ChiaSam
2 years, 5 months ago
Selected Answer: B
B is correct because if async processing is enclosed between startTest and stopTest then system collects all async and processed them as sync.
upvoted 4 times
...
drwebber
2 years, 11 months ago
The answer is B
upvoted 3 times
...
amerbearat
3 years, 3 months ago
This should be B Test.startTest and Test.stopTest are used for asynchronous apex, like Batch Apex and Future calls.
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...