Skip to content

Instantly share code, notes, and snippets.

@srujan21
Created December 31, 2019 07:01
Show Gist options
  • Save srujan21/545c85c60b48efda442bbac02767f692 to your computer and use it in GitHub Desktop.
Save srujan21/545c85c60b48efda442bbac02767f692 to your computer and use it in GitHub Desktop.
Sample Batch job along with test class
global class AccountUpdateBatchJob implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id,Name FROM Account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope)
{
for(Account a : scope)
{
a.Name = a.Name + 'Updated by Batch job';
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
@isTest
public class AccountUpdateBatchJobTest
{
static testMethod void testMethod1()
{
List<Account> lstAccount= new List<Account>();
for(Integer i=0 ;i <200;i++)
{
Account acc = new Account();
acc.Name ='Name'+i;
lstLead.add(acc);
}
insert lstAccount;
Test.startTest();
AccountUpdateBatchJob obj = new AccountUpdateBatchJob();
DataBase.executeBatch(obj);
Test.stopTest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment