Created
December 31, 2019 07:01
-
-
Save srujan21/545c85c60b48efda442bbac02767f692 to your computer and use it in GitHub Desktop.
Sample Batch job along with test class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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