You need to sign in to do that
Don't have an account?
G2WIntegration
Bug? Activating a scheduler in a test now fires the execute method as well in that test
It seems that as of Winter '12, there was a change in how tests handle scheduled jobs.
Before Winter '12, we had code that woke up a scheduler, but the execute method wasn't fired.
After Winter '12, that same code fails as the scheduler is now firing the execute method (which happens to create 2nd batch job in the same test).
Bug or expected behavior?
Example:
test.startTest(); system.schedule('Some scheduled job', varForStartTime, new someSchedulerClass()); test.stopTest();
global with sharing class someSchedulerClass implements Schedulable{ global void execute(SchedulableContext ctx) { someMethodThatFiresBatchJob(); }//execute }
Removing test.startTest() and test.stopTest() fixes the problem as then the execute method doesn't fire.
From the SFDC Apex doc:
Winter 13 (I presume you meant Winter 13, not Winter 12) is V26.0
I haven't noticed any changes as my Scheduled classes were written well before V26.0 and continue to execute correctly in Winter 13
I've never tried to schedule two identical jobs (same schedulable class) in the same testmethod
All Answers
From the SFDC Apex doc:
Winter 13 (I presume you meant Winter 13, not Winter 12) is V26.0
I haven't noticed any changes as my Scheduled classes were written well before V26.0 and continue to execute correctly in Winter 13
I've never tried to schedule two identical jobs (same schedulable class) in the same testmethod
Hmm-so I guess its always fired the execute method as long as the scheduler is run within test.startTest/stopTest(), but now that we changed the target method to a batch job, the error occured.
Thanks for the response.