You need to sign in to do that
Don't have an account?
Nishit Mistryyy
delete batch records
I have a class and I am trying to write a test class for it here is the code:
global class BatchMassDeleteDraftCaseRecs Implements Database.batchable<sobject>{
global BatchMassDeleteDraftCaseRecs(){
}
global Database.QueryLocator start(Database.BatchableContext BC){
String statusDraft = 'Draft';
String statusNew = 'New';
String statusClosed = 'Closed';
return Database.getQueryLocator('SELECT Id, Status FROM Case WHERE (Status = :statusDraft OR Status = :statusNew OR Status = :statusClosed) and FileUploadFlag__c =true');
}
global void execute(Database.BatchableContext BC,List<SObject> scope){
delete scope;
}
global void finish(Database.BatchableContext BC){
}
}
global class BatchMassDeleteDraftCaseRecs Implements Database.batchable<sobject>{
global BatchMassDeleteDraftCaseRecs(){
}
global Database.QueryLocator start(Database.BatchableContext BC){
String statusDraft = 'Draft';
String statusNew = 'New';
String statusClosed = 'Closed';
return Database.getQueryLocator('SELECT Id, Status FROM Case WHERE (Status = :statusDraft OR Status = :statusNew OR Status = :statusClosed) and FileUploadFlag__c =true');
}
global void execute(Database.BatchableContext BC,List<SObject> scope){
delete scope;
}
global void finish(Database.BatchableContext BC){
}
}
Try Below Test Class Please Mark It As Best Asnwer If It Helps
Thank You!
All Answers
Try Below Test Class Please Mark It As Best Asnwer If It Helps
Thank You!
Try the below code that gives 100% coverage
CharuDutt's code would also give 100%.The only correction would be that the testclass name should not be the same as the batch class name. Also,it is best practice and important to use
AssertEquals() that lets you test acceptance criteria in your tests. This is useful in verifying that your new feature/code is working correctly, ensuring new features did not break any existing code.
If this information helps, please mark the answer as best. Thank you
Try Below Test Class 100% Code Coverage Please Mark It As Best Asnwer If It Helps
Thank You!
Based on the code you have shared . I would suggest below modification in apex class query.
Apex test class : Please try use the below test class
For perfect test class writing Kindly refer to the below URL : https://trailhead.salesforce.com/content/learn/modules/apex_testing/apex_testing_data
If you found this answer helpful kindly mark it as best answer.
Thanks,
Karthik