+ Start a Discussion
snippets@sfsnippets@sf 

Test Class : Winter 14 Release FAILS

Below is the snippet from the test method moved successfully in production so far never had issues. but now in winter 14 it fails.

 

 

-----

Test.starttest();

ReassignmentBatch lrb = new ReassignmentBatch(strSOQL);
ID batchprocessid = Database.executeBatch(lrb,100);
System.debug('strSOQL: ' + strSOQL);
System.abortJob(batchprocessid);
Test.stoptest();

-----

 

When I comment "System.abortJob(batchprocessid);" it succeeds.  

 

But found a wierd behaviour i created only 3 records in test class for tesing but it started itterating for more than 100 of scope. and it fails.



Has anyone come accross the same.

 

May be a SF Known Issue

Best Answer chosen by snippets@sf
GunnarGunnar

You said: but it started itterating for more than 100 of scope

 

Then it is seeing more records than what you are creating in the test... Make sure that 'see all data' statement is NOT in your test.

 

. . .

 

* Again, do make sure that you create your data in the test. If you only create a couple records , then the batch should only process a couple records.

 

* Do 'comment out' that abort job.

 

* Try setting the 'version' to 27 on the class and/or test.

 

* In your production, create a *NEW* sandbox. Copy or ANT your code and test to this new sandbox. Then run test.

 

If that doesn't work, you may have to post the entire test code...

All Answers

GunnarGunnar

read this :  http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_data_access.htm

 

When batching, in the test class, create the data in the test - for the test. Don't use regular data.

This will assure the test of the batch does only one iteratin.

 

If you have this statement, get rid of it: (SeeAllData=true).

snippets@sfsnippets@sf
Thanks Gunnar. Yes i did get rid of this statement also just to test it i Added SeeAllData= false

But no Luck
GunnarGunnar

Is there a reason you are aborting the job in the test?

snippets@sfsnippets@sf

Honestly there is no reason but. an earlier devloper has designed it. and it worked upto summer 13 release. but now in winter 14 its failing.

 

so i am forced to remove this statement . but then i am getting the known itteration exception.

 

 

GunnarGunnar

You said: but it started itterating for more than 100 of scope

 

Then it is seeing more records than what you are creating in the test... Make sure that 'see all data' statement is NOT in your test.

 

. . .

 

* Again, do make sure that you create your data in the test. If you only create a couple records , then the batch should only process a couple records.

 

* Do 'comment out' that abort job.

 

* Try setting the 'version' to 27 on the class and/or test.

 

* In your production, create a *NEW* sandbox. Copy or ANT your code and test to this new sandbox. Then run test.

 

If that doesn't work, you may have to post the entire test code...

This was selected as the best answer
snippets@sfsnippets@sf

yes