You need to sign in to do that
Don't have an account?
mallikharjunarao gunda
please write a test class for batchapex calling from trigger
batch apex:
global class BatchApexDemo implements database.batchable<sobject>{
Public string soqlquery;
Public void setQry(string soqlquery){
this.soqlquery = 'Select name,status from account limit 1';
}
global database.querylocator start(database.batchableContext bc){
return database.getquerylocator(soqlquery);
}
global void execute(database.batchablecontext bd, list<sObject> sc){
System.debug('**In Execute Method**');
}
Public void finish(database.batchableContext bc){
}
}
trigger
trigger callbatchapex on Account (after insert) {
List<account> accList = new List<account>();
for(account acc : trigger.new){
if(acc.annualrevenue < 20000)
accList.add(acc);
}
if(accList.size() > 0)
database.executebatch(new BatchApexDemo(),200);
}
global class BatchApexDemo implements database.batchable<sobject>{
Public string soqlquery;
Public void setQry(string soqlquery){
this.soqlquery = 'Select name,status from account limit 1';
}
global database.querylocator start(database.batchableContext bc){
return database.getquerylocator(soqlquery);
}
global void execute(database.batchablecontext bd, list<sObject> sc){
System.debug('**In Execute Method**');
}
Public void finish(database.batchableContext bc){
}
}
trigger
trigger callbatchapex on Account (after insert) {
List<account> accList = new List<account>();
for(account acc : trigger.new){
if(acc.annualrevenue < 20000)
accList.add(acc);
}
if(accList.size() > 0)
database.executebatch(new BatchApexDemo(),200);
}
1) http://amitsalesforce.blogspot.com/2016/02/batch-apex-in-salesforce-test-class-for.html
NOTE:- I found you did not called the setQry method to set the query in your Trigger.
Update your trigger like below Your Test class like below