You need to sign in to do that
Don't have an account?

Need Help in writting Test Class for Batch Apex that deletes records?
Hi,
I need help in writting test class for this batch class, It deletes opportunity if the custom record(child to Opportunity) is not present.
Opportunity is child to Account.
Please find the codee
global class OpportunityDeleteBatch implements Database.Batchable<sObject>,Schedulable{
global void execute(SchedulableContext sc){
OpportunityDeleteBatch bc = new OpportunityDeleteBatch();
database.executeBatch(bc);
}
global Database.QueryLocator start(Database.BatchableContext bc){
return database.getQueryLocator([Select Id, Name From Opportunity WHERE RecordType.Name= 'Retail - FR' AND ID NOT IN ( Select Opportunity__c from Product_Interest__c)]);
}
global void execute(Database.BatchableContext bc,List<Opportunity> opp){
if(!opp.isEmpty()){
database.delete(opp,false);
}
}
global void finish(Database.BatchableContext bc){
}
}
I need help in writting test class for this batch class, It deletes opportunity if the custom record(child to Opportunity) is not present.
Opportunity is child to Account.
Please find the codee
global class OpportunityDeleteBatch implements Database.Batchable<sObject>,Schedulable{
global void execute(SchedulableContext sc){
OpportunityDeleteBatch bc = new OpportunityDeleteBatch();
database.executeBatch(bc);
}
global Database.QueryLocator start(Database.BatchableContext bc){
return database.getQueryLocator([Select Id, Name From Opportunity WHERE RecordType.Name= 'Retail - FR' AND ID NOT IN ( Select Opportunity__c from Product_Interest__c)]);
}
global void execute(Database.BatchableContext bc,List<Opportunity> opp){
if(!opp.isEmpty()){
database.delete(opp,false);
}
}
global void finish(Database.BatchableContext bc){
}
}
Update your RecordTypeID for Retail - FR in the above code and this will cover your Batch class 100%.