function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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