2

I am going through Apex Governor Limits that Affect Flows documentation and came across two new terms "larger transaction" and "batch transaction". I thought we only have Synchronous transaction, Asynchronous transaction(slightly higher limits than synchronous). What are these?

Quoting the text:

1 Autolaunched flows are part of the larger transaction through which they were launched. For example, flows launched from a process are executed with the process actions as part of the larger transaction. Flows with Screen elements can span multiple transactions. A new transaction begins each time the user clicks Next in a screen. Flows with Wait elements span multiple transactions. A transaction ends when a flow interview begins to wait for an event. When the flow interview resumes, a new transaction begins. Everything after the Wait element is executed as part of a batch transaction that includes other resumed interviews.

1 Answer 1

3

What it's getting at here is that each Flow is not its own independent transaction. If it's an autolaunched Flow, it's executing as part of the transaction for whatever functionality launched it - so if you go from Process Builder, for example, into an autolaunched Flow, the two elements take place in the same transaction.

Waiting Flow interviews are resumed in batches. When a Flow Wait element is ready to resume, Salesforce opens a batch and waits up to an hour to accumulate more resuming Flow interviews, which are executed together in a single transaction. More details here - the words "batch" and "transaction" are, confusingly, used interchangeably in the documentation on this.

2
  • Thanks. To better understand this, I am running a script from anonymous apex window and script does this: 1) Create 10000 leads and insert them 2) next, invoke a autolaunched flow, which will create two lead records. When I run this script, it is running as one transaction(because it shows only one debug log) and I see in the system that there are 10002 lead records created. Here is the code : pastebin.com/vu8a6DDE More than 10000 DML records shouldn't be allowed in one transaction right?
    – javanoob
    Commented Jan 6, 2018 at 21:51
  • I don't immediately have an explanation of why that does not throw an exception - I'd expect it to. Do you observe the same behavior outside of Anonymous Apex? There are some ways in which Anonymous doesn't replicate standard Apex behavior, although I wasn't aware this was one of them.
    – David Reed
    Commented Jan 6, 2018 at 21:59

You must log in to answer this question.

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