I have a trigger after insert on some arbitrary entity:
trigger OpportunityTrigger on Opportunity (after insert) {
// not bulkified for the sake of simplicity
ID jobID = System.enqueueJob(new CalloutJob());
insert new Callout__c(JobID__c = jobID, Payload__c = Trigger.new[0]));
}
and the CalloutJob class that implements Queueable:
public class CalloutJob implements Queueable {
public void execute(QueueableContext ctx) {
// find the related Callout record
Callout__c callout = [Select Id, Payload__c From Callout__c Where JobID__c = :ctx.getJobId()];
// and do some fancy processing based on the callout object
}
}
Is it guaranteed that the insert DML operation runs before the CalloutJob is executed? In other words - is it guaranteed that the SELECT statement always finds the related callout record?
I did some initial tests on ~20 records and it seems just fine. But I couldn't find any unambiguous official documentation on that.