[SalesForce] Is asynchronous apex either rolled back or not executed if the original transactions fails

I would like to confirm the behaviour of asynchronous apex when an error occurs on its original/parent transaction.

Imagine we have a synchronous apex transaction (Transaction1-Apex) that launches a apex batch process (Transaction2-Batch).

Can I assume that if there is a uncatched exception in Transaction1-Apex after the executeBatch method has been called, the platform will also rollback or even not execute Transaction2-Batch?

Here is a more "graphical" representation of what I mean:

Database.executeBatch(...)          Transaction2-Batch
-                                           -
-                                           -
-                                           -
Uncatched exception                         -
-- Automatic rollback                       ... is this transaction also rolled back?

I assumed that was the case, asynchronous apex was always rolled back.
However, I could not find confirmation in the official docs, then I found the following article indicating that there are some cases where this might not be true:

Has anyone investigated this in depth? If so, could you confirm or deny my hypothesis?

Thanks a lot everyone!

Best Answer

My understanding is that for most asynchronous invocations - including future, Queueable, Batchable, Schedulable - the invocation enqueues the operation but it does not execute until the end of the current synchronous Apex transaction. In case of an unhandled exception, these jobs are rolled back from the queue and don't execute.

However not all features work this way. Notably if you fire a Platform Event from a transaction that subsequently rolls back or has an unhandled exception, the Event (and any triggers on it, executed asynchronously) will continue unaffected.