New Year Sale Special Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: xmasmnth

The test method calls an @future method that increments a value.

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.

Salesforce PDII Summary

  • Vendor: Salesforce
  • Product: PDII
  • Update on: Dec 26, 2025
  • Questions: 161
Price: $52.5  $149.99
Buy Now PDII PDF + Testing Engine Pack

Payments We Accept

Your purchase with ExamsVCE is safe and fast. Your products will be available for immediate download after your payment has been received.
The ExamsVCE website is protected by 256-bit SSL from McAfee, the leader in online security.

examsvce payment method