You need to sign in to do that
Don't have an account?
Szymon
Hel with Test Class
Hi, I'm trying to write a test class for the below:
global class EmptyDeletedRecords implements Database.Batchable<sObject>, Schedulable{ global EmptyDeletedRecords(){} global Database.QueryLocator start(Database.BatchableContext bc){ return Database.getQueryLocator([Select id from Deleted_record__c where CreatedDate <LAST_N_DAYS:5]); } //Execute method for the Schedulable interface global void execute(SchedulableContext sc){ //execute the batch EmptyDeletedRecords deleteCS = new EmptyDeletedRecords(); ID batchprocessid = Database.executeBatch(deleteCS); } //Execute method for the batchable interface global void execute(Database.BatchableContext BC, list<sObject> scope){ delete scope; DataBase.emptyRecycleBin(scope); } global void finish(Database.BatchableContext BC){} }But am not sure how to test the scope deletion:
@isTest private class EmptyDeletedRecords_Test{ @testSetup static void setupTestData(){ test.startTest(); Deleted_record__c deleted_record_Obj = new Deleted_record__c(Deleted_ID__c = '5001p00002O54P2AAJ', External_ID__c = 'null', Object_Type_From_Apex__c = 'Case_with_custom_object'); Insert deleted_record_Obj; test.stopTest(); } static testMethod void testBatch(){ SchedulableContext sc = null; EmptyDeletedRecords tsc = new EmptyDeletedRecords(); tsc.execute(sc); } }Any advice how to test that? Thanks!
private class EmptyDeletedRecords_Test{
@testSetup
static void setupTestData(){
test.startTest();
List<Deleted_record__c> listRec = new list<Deleted_record__c>();
for(Integer i = 0 ;i<10;i++){
Deleted_record__c deleted_record_Obj = new Deleted_record__c(
Deleted_ID__c = '5001p00002O54P2AAJ', External_ID__c = '21376761237'+i,
Object_Type_From_Apex__c = 'Case_with_custom_object');
listRec.add(deleted_record_Obj);
}
Insert listRec;
EmptyDeletedRecords obj = new EmptyDeletedRecords ();
DataBase.executeBatch(obj , 10);
test.stopTest();
}
}
Please check once below snippet code:
I think records are not retrieving please check once records are displaying in debug logs or not.
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Raj, there's no error only 0% code coverage on the class.
Thanks