+ Start a Discussion
Ayyagari RameshAyyagari Ramesh 

batch class to delete reports which are 6 months old

Hi All, 

I have written a batch class and the scenerio is to delete the unused reports which are 6 months old. User-added imageI am getting repeated errors, not sure where i am going wrong
Please find the below code  and do let me know if  any changes required to be made.

Batch Class :

global class BatchMassDeleteReports implements Database.Batchable<sObject>{
    

    public Database.QueryLocator start(Database.BatchableContext context)
    {
        return Database.getQueryLocator('Select ID from Report where LastRunDate <= LAST_N_DAYS:180');
    }

    public void execute(Database.BatchableContext context, List<Report> records)
    {
        delete records;
    }
   public void finish(Database.BatchableContext){
        
    }
}  


Also find the schedule class below :


public DeleteReportSchedulerClass() {
    }
    
    global void execute(SchedulableContext sc){
        try{
            //Executing batch class (size:50).
            BatchMassDeleteReports batchApexSchd = new BatchMassDeleteReports();   
            database.executebatch(batchApexSchd, 50);
            
            }catch(exception ex){
             //Catching any exception that occurs.
            System.Debug('There was an error ' + ex.getMessage());
            }
    }




Thanks, 
Ramesh
@anilbathula@@anilbathula@
Hi Ramesh,

You cant delete reports with apex,delete call is not supported on report.
You can only do these operations (describeSObjects(), query(), retrieve(), search()) on reports.

Thanks
Anil.B