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 # 23 Topic 3 Discussion

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

PDII Exam Topic 3 Question 23 Discussion:
Question #: 23
Topic #: 3

The test method calls an @future method that increments a value. The assertion is failing because the value equals 0. What is the optimal way to fix this?

Java

@isTest

static void testIncrement() {

Account acct = new Account(Name = 'Test', Number_Of_Times_Viewed__c = 0);

insert acct;

AuditUtil.incrementViewed(acct.Id); // This is the @future method

Account acctAfter = [SELECT Number_Of_Times_Viewed__c FROM Account WHERE Id = :acct.Id][0];

System.assertEquals(1, acctAfter.Number_Of_Times_Viewed__c);

}


A.

Change the assertion to System.assertEquals(0, acctAfter.Number_Of_Times_Viewed__c).


B.

Add Test.startTest() before and Test.stopTest() after insert acct.


C.

Change the initialization to acct.Number_Of_Times_Viewed__c = 1.


D.

Add Test.startTest() before and Test.stopTest() after AuditUtil.incrementViewed.


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.