anusha(salesforce developer)

Thursday, 15 September 2016

How to write test class for Database.QueryLocator in Batch Apex?

How to write test class for Database.QueryLocator in Batch Apex?

Sample Batch Class:



Test class for above Batch Class:

@isTest
public class AccountUpdateTest {
    static testMethod void test() {
        Database.QueryLocator QL;
        Database.BatchableContext BC;
        List<Account> AcctList = new List<Account>();
        AccountUpdate AU = new AccountUpdate('Name', 'Test');
        QL = AU.start(bc);
       
        Database.QueryLocatorIterator QIT =  QL.iterator();
        while (QIT.hasNext())
        {
            Account Acc = (Account)QIT.next();           
            System.debug(Acc);
            AcctList.add(Acc);
        }       
       
        AU.execute(BC, AcctList);
        AU.finish(BC);       
    }
}

No comments:

Post a Comment