1

I have a scheduled job named "Scheduled_Mail" and its class is "Scheduled_Mail_Controller". From February 13, suddenly the following error occurs.

'Scheduled_Mail' : Dependent class is invalid and needs recompilation: Class Schedule_Notice_Batch_Controller : DML operation Delete not allowed on List<Notification__c>

Scheduled_Mail_Controller

global without sharing class Scheduled_Mail_Controller implements Schedulable {
    global void execute(SchedulableContext ctx) {
        Schedule_Notice_Batch_Controller noticeBatch = new Schedule_Notice_Batch_Controller();
        Database.executeBatch(noticeBatch, 200);

Schedule_Notice_Batch_Controller

    public without sharing class Schedule_Notice_Batch_Controller implements Database.Batchable<sObject>{
    
    public Database.QueryLocator start(Database.BatchableContext bc) {
        String query = 'SELECT Id,CreatedDate FROM Notification__c ORDER BY CreatedDate DESC';
        return Database.getQueryLocator(query);
    }

    public void execute(Database.BatchableContext bc, List<sObject> targetRecords) {
        List<Notification__c> deleteNoticeList = new List<Notification__c>();
        for(sObject s: targetRecords){
            if((Datetime)s.get('CreatedDate')<=System.today().addDays(-90)){
                deleteNoticeList.add((Notification__c)s);
            }
        }
        
        if(deleteNoticeList.size()>0){
            if (Notification__c.sObjectType.getDescribe().isDeletable()){
                delete deleteNoticeList;
            }
        }
    }
    
    public void finish(Database.BatchableContext bc) {
    }
}

If you know how to solve this problem, please kindly tell me. Thank you.

1
  • 2
    Can you check if there is any delete operation trigger on the custom object you are trying to delete? Feb 18, 2022 at 8:15

1 Answer 1

0

This started failing in Spring '22. We have recently encountered this problem, too. This happens if you schedule a job from PostInstallHandler (my related question: Debug Logs for PostInstallHandler SuperUser).

For me, it helped to build new version of app in which I aborted previously scheduled jobs (that were scheduled from PostInstallHandler by a SuperUser mentioned in this question) and added possibility to run this scheduled job from real System Administrator (in my case - it is an Apex method called from VF page).

So the actual solution is to reschedule your jobs under actual System Administrator that has permissions on your managed package custom object on delete.

2
  • 1
    Thank you for your advice. Your solution worked and helped me a lot! And also as I thought it was Salesforce's bug, I opened a case about this issue and today Salesforce Support said they had resolved this bug. Now I confirmed the bug is fixed.
    – wanwan
    Mar 7, 2022 at 4:19
  • Cool, thank you for the update, I'll try it too! Mar 7, 2022 at 7:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .