3

If a public class implements both Schedulable and Queueable interface

public class A implements Schedulable, Queueable {
    public void execute(SchedulableContext c) {
        //
    }
    public void execute(QueueableContext c) {
        //
    }
}

and then this class is enqueued,

System.enqueueJob(new A());

a run-time error is displayed

Line: 1, Column: 1
System.AsyncException: Queueable cannot be implemented with other system interfaces.

Why this error is displayed as run time instead of compile error?

Why it is allowed to define a class which implement both interfaces but the run time error is only displayed when this class instance is enqueued but not when it is scheduled?

Why there is no error when a class implements both Batchable and Schedulable and a method to run or schedule a batch is executed?

Is there any workaround to this problem?

1 Answer 1

4

Looks like this is another unexplained weirdness of Salesforce system.

However, if a Queueable class is declared as an inner class,

public class A implements Schedulable  {
    public class B implements Queueable{
        public void execute(QueueableContext c) {
            //
        }
    }
    public void execute(SchedulableContext c) {
        //
    }
}

then enqueueing it doesn't bring any error and is executed successfully

System.enqueueJob(new A.B());
1
  • 1
    Seems like a silly limitation, there are plenty of good reasons to schedule a job that can re-enqueue itself. This solution of an inner class for the Queueable is excellent. Jun 12, 2023 at 21:44

You must log in to answer this question.

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