function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MachhiMachhi 

Test method for mass records update failed

I am trying to write a test method for mass update utility.

It simply calls a future method. Please see below code snippet:

.....
.....
//Run the method for Contact update utility
Test.startTest();
CustomUtilityHelper.ContactUpdateUtility(DateTime.now().year()+ '',1,true,false);
Test.stopTest();

//Assert the count for cases against the above contact record
Decimal numberOfcasesForContact = [select Id, Number_of_Cases__c from contact where id=:PrimaryContact.id].Number_of_Cases__c;
System.debug('Test case count against contact :' + numberOfcasesForContact);
System.assert(numberOfcasesForContact==1, 'Test case count against contact failed.');
.....
.....

This CustomUtilityHelper.ContactUpdateUtility() method loops through all contact records in the system for current year.
My organization have near about 3000 contact records. So I choose to use Future call.

Can any one please advice me whether this will work from the past experience? This test method validates positive test, then negative test and hence the above call is made twice or thrice or more. So this results in number of SOQL queries increased resulting in failure of test method.

Does anybody know best practices to write test method for such type of requirement?

Thanks in advance.
WesNolte__cWesNolte__c

Hey

 

I assume you're hitting a governor limit? So what you'd like to do is run each test independently? Annoying isn't it.. the quickest fix I can think of is to put each test method into it's own test class, and run each one individually.

 

Wes