Consider the following class:
public inherited sharing class testQueueableSharing implements Queueable {
public void execute(QueueableContext context) {
update [SELECT Id FROM User WHERE Name='User User'];
}
}
Which is invoked from a trigger, by a standard user:
trigger TestTriggerExecutePolicy on Lead (before insert, before update, before delete, after insert, after update, after delete) {
System.enqueueJob(new testQueueableSharing());
}
Will throw an exception, while declaring class without sharing or calling update from trigger directly succeeds.
Does queueable apex not support inherited sharing? Isn't this something that at least the compiler should catch?
with sharing
if the caller hasn't specified it which in this case is a trigger, whereas code called from a without any declaration of sharing class runs without sharing. Also a best practice is to have a trigger handler call the queueable instead of trigger calling it directly to avoid this side effect.