0

When I raised another question, it was brought to my attention that events are not guaranteed to be delivered at all times. Is Queueable Apex / Batch Apex / Future Methods so long as from an update/insert trigger guaranteed to eventually run even if you don't know precisely when it will run.

1 Answer 1

2

General execution of successfully queued/invoked batches, queueables and futures is guaranteed (importantly the initiating transaction must have successfully committed and finished first), though as the documentation says there's no guarantee on SLA - it could take quite a long time for the logic to be processed - nor the ordering of execution.

I have not seen anything that contradicts this. That said, I don't know how Salesforce handles such async processing if the host instance were to die half way through its execution (I don't even know what would happen in the async jobs table). I'm quite sure @sfdcfox will have something to say on this.

The same level of service can generally be said for schedulables. However, for the latter (which may include scheduled batches) there's a platform bug that we identified and that I hope Salesforce will actually fix, that means single-execution schedulables that are scheduled for a future time that is close to "now" are currently not guaranteed to be invoked. You can read more about this here, and vote for a fix (yeah, tl;dr this shouldn't be an idea, but that's what SF support told me to do).

In normal use, especially on a production org, async process initiation happens pretty soon (seconds to minutes) after you wanted it unless your org starts being throttled due to going over limits etc. (Salesforce started making some limits a bit more flexible over the last year or two; whereas before you would get an uncatchable exception when trying the add an async job when you have already created too many in the day, now you're given some leeway.)

Even for scheduled executions these are usually invoked within a few minutes of when you asked.

We have, however, seen cases where these have been delayed by over 15 minutes from the requested start time.

4
  • yeah but so long as its initial transaction doesn't have an unhandled exception it will "eventually" happen? Is there any max time like are we talking minutes/hours/days/weeks months? I would hope that the host dying would be exceptionally rare and even if it did happen would this be reflected inside the AsyncApexJob Object? Commented Mar 26, 2021 at 16:29
  • @KarlLivesey responded by updating my answer.
    – Phil W
    Commented Mar 26, 2021 at 16:41
  • 1
    +1 I agree with this answer. Barring some weird edge cases, like the host being shut down, governor limits, or your weird scheduled apex edge case, async executions are essentially guaranteed, but I don't think the documentation specifically says that.
    – sfdcfox
    Commented Mar 26, 2021 at 18:50
  • @sfdcfox to be honest I don't mind if they get dropped I just need to know that they have been dropped as it makes debugging a nightmare. Commented Mar 28, 2021 at 14:10

You must log in to answer this question.

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