You need to sign in to do that
Don't have an account?
CBN
How to write test class for batch apex for following code
global class Batch_UpdateAcc implements Database.Batchable<sObject>{
List <Account> mapAccount = new List <Account> ();
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('SELECT ID, BillingCountry, ShippingCountry FROM Account');
}
global void execute(Database.BatchableContext bc, List<Account> scope){
for(Account acc : scope){
if(acc.BillingCountry=='UK'){
acc.BillingCountry = 'United Kingdom';
}
if(acc.ShippingCountry=='UK'){
acc.ShippingCountry = 'United Kingdom';
}
if(acc.BillingCountry=='USA'){
acc.BillingCountry = 'United States';
}
if(acc.ShippingCountry=='USA'){
acc.ShippingCountry = 'United States';
}
mapAccount.add(acc);
}
UPDATE mapAccount;
}
global void finish(Database.BatchableContext bc){
}
}
List <Account> mapAccount = new List <Account> ();
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('SELECT ID, BillingCountry, ShippingCountry FROM Account');
}
global void execute(Database.BatchableContext bc, List<Account> scope){
for(Account acc : scope){
if(acc.BillingCountry=='UK'){
acc.BillingCountry = 'United Kingdom';
}
if(acc.ShippingCountry=='UK'){
acc.ShippingCountry = 'United Kingdom';
}
if(acc.BillingCountry=='USA'){
acc.BillingCountry = 'United States';
}
if(acc.ShippingCountry=='USA'){
acc.ShippingCountry = 'United States';
}
mapAccount.add(acc);
}
UPDATE mapAccount;
}
global void finish(Database.BatchableContext bc){
}
}
Best Answer chosen by CBN
Raj Vakati
try this code