If you want to take your Salesforce Flow skills to the next level, it’s inevitable that you will need to start familiarizing yourself with “general” and “governor” limits.
These limitations can seem intimidating at first, but I will explain the most important concepts and the most common constraints (as well as how to avoid hitting Salesforce Flow limits) in plain language to help you understand more easily.
Before we get started, there are a few concepts that you need to know.
Why are there limitations?
Salesforce is a multitenant environment, which means that multiple orgs share the resources of the same instance. To make sure no one occupies too much capacity, Salesforce has enforced these limitations to govern the usage for each client.
What are Flow interviews and transactions?
An interview is a running instance of a flow, which is one complete run of that flow. A transaction, on the other hand, is a set of operations executed as a single unit. Flow interview is one of the types of operations besides triggers, escalation rules, etc. This means that a flow interview is always running inside a transaction.
However, multiple flow interviews can run in the same transaction, and one flow interview can also run in many transactions. The first case is because of the Flow bulkification, and the second depends on what is considered as a “single unit”. I will explain these further, but for now, it is important to remember that a flow interview is not a transaction and different sets of limitations apply.
What are SOQL and DML?
SOQL and DML are two languages that handle different operations. SOQL is for retrieving data, and DML is for modifying data. In Flow, only the data elements (the pink ones) will call for these operations – “Get Records” uses SOQL, and “Create/Update/Delete Records” uses DML with some variation. You can find the explanations in my videos.
While it’s nice to know all of the Salesforce Flow limits, let’s focus on the limits you are more likely to hit in the early stages:
Limits Per Flow Interview
- Executed elements at runtime per flow: 2,000
- For each flow interview, you can only have a maximum of 2,000 elements being executed. Note that if you have a loop, the elements within the loop (including the loop element) will be multiplied by the number of iterations. For example, if you have 100 records that enter a loop with two elements, the total elements will be 200.
Note: In API version 57.0, the limit of 2,000 flow elements was removed. In API version 56.0 and earlier, flows could have a maximum of 2,000 flow elements. Ensure your flows are on the most recent API version to make use of this.
Limits Per Transaction
- Total number of SOQL queries issued: 100
- You can only use a maximum of 100 data elements that retrieve the data.
- Total number of DML statements issued: 150
- You can only use a maximum of 150 data elements that modify the data. (Note that these elements will also be multiplied if they are within the loop, which is why you often hear the best practice is “No Pink in Loop”.)
- Total number of records retrieved by SOQL queries: 50,000
- You can only retrieve a maximum of 50,000 records.
- Total number of records processed as a result of DML statements: 10,000
- You can only modify a maximum of 10,000 records.
- Maximum CPU time on the Salesforce servers: 10,000 milliseconds
- CPU time is the amount of time that the servers use to process your solution. The maximum is 10,000 milliseconds (10 seconds).
- Total number of duplicate updates allowed in one batch: 12
- You can only update the same record a maximum of 12 times.
How to Avoid Hitting the Limits
First and foremost, you have to make sure you build the flow in the most efficient way possible. But what if the flow is still hitting the limits after all the best practices have been followed? The answer is easier than you might think – since the limits are per flow interview or transaction, we can try to generate multiple flow interviews or transactions.
How to Build an Efficient Flow
It is a good habit to always think about how to make your flows more efficient. By following these practices, you may not even encounter the problem of hitting the limits:
- Avoid overusing data elements.
- Try not to use data element in loop.
- Skip the loop if possible.
- Make entry criteria strict.
- Utilize variables and Assignment element for updating records.
Generate More Flow Interviews
When handling a larger amount of data, people usually hit the element limit first before the number of records limit. To prevent this, utilize the bulkification feature of Record-Triggered (RT) and Schedule-Triggered (ST) Flow.
Bulkification is a complex topic, but try to remember this advice: Build your RT/ST flow as if it is for one record for the triggering object. Salesforce will then batch the records whenever it can. This can help you effectively avoid the element constraint – you can take a look at my experiment if you want to dig a little deeper.
Generate More Transactions
Even if you avoid the flow interview limit, you might still hit the transaction limit. To avoid this, you can try to generate multiple transactions. Back to the definition of “single unit” – we can understand this as the operations that can be executed without a pause.
Screen elements, scheduled paths, and pause actions will all pause the flow interview. The rest of the flow interview will then run in a new transaction. This is a nice little trick to know, but do note that once a transaction is finished, you can’t roll back the operations – this is because they are already committed.
Salesforce Flow limits are in place to make sure each client can utilize the resources fairly. In general, there are two sets of limitations (per flow interview and per transaction), which are two different concepts. To avoid these limits, build the flows as efficiently as possible, utilize the bulkification feature, or split the transactions.
This article has covered only the most common limits. If you are interested in learning about all of the general limits, please take a look at the official documentation and further resources:
- General Flow Limits
- Per-Transaction Flow Limits
- Flow Interview Definition
- Flow in Transaction
- Flow Bulkification in Transactions