+ Start a Discussion
Lee SinLee Sin 

Two questions on Batch Apex


1. I wrote a test class for the batch apex class.  The result is not as expected so I want to watch the variables in Batch Class.

global class AR_Creating75DummyNML implements Database.Batchable<sObject>{

global final String query;
global AR_Creating75DummyNML(String q)
    {
        query=q;
    } 
global Database.QueryLocator start(Database.BatchableContext BC)
    {        
        return Database.getQueryLocator(query);        
    }

global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        System.debug(scope.size());


      .........
}
}

I want to watch the size of the List passed from start method to execute method.
But when I run the test class, it only shows the variables in the test method. How can I watch the variable scope?

2.  Am I using System.abortJob correctly?
Test.startTest();
        AR_Creating75DummyNML c=new AR_Creating75DummyNML(query);
        ID batchID=Database.executeBatch(c);
        System.abortJob(batchID);
        Test.stopTest();
I got an error (No more than one executeBatch can be called from withink a testmethod.)  before I used System.abortJob.
So does this mean if the scope size is over 200, I have to use this System.abortJob(batchID)?