---
schema_version: "1"
id: 85c645f840a057e9675f4968012f690c3fcee42da874e18a4897352b528cd6a4
title: Troubleshoot APEX_CPU_TIME_LIMIT_EXCEEDED Errors in Flows
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/automate_flow_troubleshoot_cpu_limit.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.automate_flow_troubleshoot_cpu_limit.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 3c18f65f468f9dd5134418aa4acc2552f7638c042577ae5292444974e74235aa
description: When a transaction consumes too much CPU time, Salesforce throws an APEX_CPU_TIME_LIMIT_EXCEEDED error. Flows share this limit with every other automation in the same transaction, including Apex triggers.
products:
  - Flow Builder
  - Salesforce Platform
release: "264"
---
# Troubleshoot APEX\_CPU\_TIME\_LIMIT\_EXCEEDED Errors in Flows

When a transaction consumes too much CPU time, Salesforce throws an APEX\_CPU\_TIME\_LIMIT\_EXCEEDED error. Flows share this limit with every other automation in the same transaction, including Apex triggers.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=platform.flow_ref_supported_editions.htm&amp;release=264.0.0&amp;type=5" title="Learn about the editions and user interfaces that support Flow Builder. Some Flow Builder features integrate with other Salesforce products that require additional licenses.">View supported editions.</a></td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:left;vertical-align:top;" id="d158466e61">User Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e61 ">To open, edit, create, activate, or deactivate a flow using all flow types,
              elements, and features available in Flow Builder, including Einstein and Agentforce
              for Flow:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e61 ">Manage Flow</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e61 ">To view Setup and access debug logs:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e61 ">View Setup and Configuration</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e61 ">To view, retain, and delete debug logs, and set trace flags:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e61 ">View All Data</td>

          </tr>
        </tbody>
      </table>

Salesforce enforces a single CPU time limit of 10,000 milliseconds (10 seconds) per synchronous transaction. Every piece of automation in that transaction, such as Apex triggers, flows, workflow rules, and processes, draws from the same budget. If other automation consumes most of the budget first, even an optimized flow can fail. Execution order depends on flow type. For the full order, see [Triggers and Order of Execution](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm).

- Before-save flows run earlier in the order than after-save flows.
- Apex triggers run before or after flows depending on their trigger type.

To troubleshoot and optimize flows that hit CPU time limits:

- Understand the common patterns that cause CPU limit errors
- Identify which elements consume the most CPU time
- Apply optimization techniques to reduce CPU consumption
- Implement prevention guidelines to avoid CPU limit errors

- **[Problems, Solutions, and Prevention Techniques for CPU Limit Errors](https://help.salesforce.com/s/articleView?id=platform.automate_flow_troubleshoot_cpu_limit.htm&release=264.0.0&type=5)**  
    Identify common CPU limit problems, apply solutions, and follow prevention techniques to avoid APEX\_CPU\_TIME\_LIMIT\_EXCEEDED errors.
- **[Identify CPU-Intensive Elements in a Flow](https://help.salesforce.com/s/articleView?id=platform.automate_flow_troubleshoot_cpu_limit.htm&release=264.0.0&type=5)**  
    Use Apex debug logs to pinpoint which elements in your flow consume the most CPU time.

#### See Also

- [Flow Bulkification in Transactions](https://help.salesforce.com/s/articleView?id=platform.flow_concepts_bulkification.htm&release=264.0.0&type=5 "When a flow runs for multiple records at the same time, Salesforce creates one flow interview per record. Bulkification groups similar operations when interviews for the same flow reach the same element, helping the transaction use fewer queries and statements.")
- [Plan for Success with Flow Builder Best Practices](https://help.salesforce.com/s/articleView?id=platform.flow_prep_bestpractices.htm&release=264.0.0&type=5 "Before you build and distribute flows, plan your approach. To minimize errors and rework, follow these Flow Builder guidelines.")
- [Flow Limits per Org](https://help.salesforce.com/s/articleView?id=platform.flow_considerations_limit.htm&release=264.0.0&type=5 "Review per-org, per-interview, and marketing flow limits, including limits for flow versions, active flows, scheduled interviews, and heap size.")
- [Transform Element](https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_transform.htm&release=264.0.0&type=5 "Select the flow resources for mapping and transforming source data to target data. You can use the Transform element in screen flows, autolaunched flows with no triggers, and record-triggered flows.")

## Problems, Solutions, and Prevention Techniques for CPU Limit Errors

Identify common CPU limit problems, apply solutions, and follow prevention techniques to avoid APEX\_CPU\_TIME\_LIMIT\_EXCEEDED errors.

This table provides a reference for troubleshooting CPU limit errors. Each row describes a common problem, the solution to fix it, and techniques to prevent it in future flows. Start by determining whether any of these problems apply to your flow. If none apply, another automation in the same transaction—such as an Apex trigger, another flow, or a workflow rule—draws from the same CPU budget and can be the culprit. To identify what's consuming CPU across the entire transaction, review the Apex debug logs. For more details, see [Debug Logs](https://help.salesforce.com/s/articleView?id=platform.code_debug_log.htm&type=5&language=en_US).

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
          <colgroup>
            <col style="width:33.33333333333333%">
            <col style="width:33.33333333333333%">
            <col style="width:33.33333333333333%">
          </colgroup>
          <thead class="slds-text-title_caps ">
            <tr class="">
              <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d158466e237">Problem</th>
              <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d158466e240">Solution</th>
              <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d158466e243">Prevention Technique</th>
            </tr>
          </thead>
          <tbody>
            <tr class="">
              <td data-label="Problem" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e237 ">
                <p><strong>Data Manipulation Language (DML) Operations Inside Loops</strong></p>
                <p>Performing Create Records, Update Records, or Delete Records operations inside a
                  loop path consumes CPU time with each iteration. Processing multiple records one at
                  a time can quickly exhaust the limit.</p>
                <p style="margin-bottom:0;"><strong>Example:</strong> A flow loops through 100 opportunities and uses a Create Records
                  element inside the loop to create a task for each opportunity, resulting in 100
                  separate DML operations.</p>
              </td>

              <td data-label="Solution" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e240 ">
                <p><strong>Use Collection-Based Data Manipulation Language (DML) Operations</strong></p>
                <p>Inside the loop, use Assignment elements to add records to a record collection
                  variable. After the loop completes, use a single Create Records, Update Records, or
                  Delete Records element to process the entire collection at once. This approach is
                  called bulkification.</p>
                <p><strong>Example:</strong> Loop through opportunities, use an assignment element to build a
                  task for each opportunity. Then use another assignment element to add each task to a
                  collection variable. After the loop, use a Create Records element to create all
                  tasks at once.</p>
                <p style="margin-bottom:0;">For more information, see <a href="https://help.salesforce.com/s/articleView?id=platform.flow_concepts_bulkification.htm&amp;release=264.0.0&amp;type=5" title="When a flow runs for multiple records at the same time, Salesforce creates one flow interview per record. Bulkification groups similar operations when interviews for the same flow reach the same element, helping the transaction use fewer queries and statements.">Flow Bulkification in Transactions</a>.</p>
              </td>

              <td data-label="Prevention Technique" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e243 ">
                <p style="margin-bottom:0;">Never place DML operations inside loops. Always design flows to collect records in
                  a collection variable during the loop, then perform DML after the loop
                  completes.</p>
              </td>

            </tr>
            <tr class="">
              <td data-label="Problem" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e237 ">
                <p><strong>Multiple Queries Inside Loops</strong></p>
                <p>Get Records elements inside a loop consume significant CPU time, especially when
                  querying large objects or using complex filters.</p>
                <p style="margin-bottom:0;"><strong>Example:</strong> A flow loops through accounts and uses Get Records inside the loop
                  to get related contacts for each account, resulting in one query per account.</p>
              </td>

              <td data-label="Solution" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e240 ">
                <p><strong>Query Data Before Loops</strong></p>
                <p>Before the loop, use a single Get Records element and use the get related records
                  functionality to get all necessary data with appropriate filters. During the loop,
                  use the collected data rather than querying on each iteration. If you can't use a
                  single Get Records element, use a Get Records element to get the primary records.
                  Then, use another Get Records element to get the secondary records. Filter the
                  secondary records using a record field, the In operator, and the first Get Records
                  collection. For example, Account ID &gt; In &gt; Accounts from Get Accounts. </p>
                <p style="margin-bottom:0;"><strong>Example:</strong> First get all related contacts with a Get Records element that
                  filters by the account IDs, then reference the contacts collection during the
                  loop.</p>
              </td>

              <td data-label="Prevention Technique" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e243 ">
                <p style="margin-bottom:0;">Avoid queries inside loops. Get all necessary data before entering the loop.</p>
              </td>

            </tr>
            <tr class="">
              <td data-label="Problem" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e237 ">
                <p><strong>Complex Formulas in Loops</strong></p>
                <p>Assignment elements that run complex formula calculations on each loop iteration
                  accumulate CPU time, particularly with string manipulation, date calculations, or
                  nested functions.</p>
                <p style="margin-bottom:0;"><strong>Example:</strong> A flow loops through 500 records, and each iteration performs
                  multiple formula calculations to derive field values.</p>
              </td>

              <td data-label="Solution" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e240 ">
                <p><strong>Simplify Formulas</strong></p>
                <p>Break complex formulas into simpler steps. Calculate values that don't change
                  outside the loop. Avoid nested functions when possible. Consider using formula
                  fields on the object instead of flow formulas.</p>
                <p>For operations on entire collections—such as filtering, mapping, or sorting—a
                  Transform element performs more efficiently than a loop. To get all related records
                  in a single query instead of one query per loop iteration, use a Get Records element
                  with the IN operator.</p>
                <p style="margin-bottom:0;">For more information, see <a href="https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_transform.htm&amp;release=264.0.0&amp;type=5" title="Select the flow resources for mapping and transforming source data to target data. You can use the Transform element in screen flows, autolaunched flows with no triggers, and record-triggered flows.">Transform Element</a>.</p>
              </td>

              <td data-label="Prevention Technique" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e243 ">
                <p style="margin-bottom:0;">Simplify formulas and move calculations that don't change outside the loop. Test
                  formula performance with realistic data volumes.</p>
              </td>

            </tr>
            <tr class="">
              <td data-label="Problem" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e237 ">
                <p><strong>Processing Large Record Collections</strong></p>
                <p>Scheduled flows or batch operations that process thousands of records in a single
                  transaction, even with proper bulkification, can consume too much CPU time.</p>
                <p style="margin-bottom:0;"><strong>Example:</strong> A scheduled flow gets 5000 account records and performs complex
                  transformations on each record's data before updating them.</p>
              </td>

              <td data-label="Solution" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e240 ">
                <p><strong>Use Alternative Approaches</strong></p>
                <p>For large data volumes, consider:</p>
                <ul>
                  <li>Breaking the work into multiple scheduled flows that each process a subset of
                    records</li>

                  <li>Using Apex batch processing for extreme data volumes</li>

                  <li>Processing records incrementally over time</li>

                  <li>Using Platform Events to distribute processing across multiple transactions</li>

                </ul>
              </td>

              <td data-label="Prevention Technique" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e243 ">
                <p style="margin-bottom:0;">Filter data early to reduce the number of records processed. Use Get Records
                  filters to get only the records you need. Test with realistic data volumes before
                  deploying to production.</p>
              </td>

            </tr>
            <tr class="">
              <td data-label="Problem" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e237 ">
                <p><strong>Multiple Flows in a Transaction</strong></p>
                <p>When one flow triggers other flows (through record changes or subflows), the
                  cumulative CPU time of all flows in the transaction counts toward the limit.</p>
                <p style="margin-bottom:0;"><strong>Example:</strong> A record-triggered flow on Account updates runs multiple subflows
                  and also triggers other record-triggered flows on related objects.</p>
              </td>

              <td data-label="Solution" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e240 ">
                <p><strong>Reduce Flow Chains</strong></p>
                <p style="margin-bottom:0;">Consolidate related automation into fewer flows. Review your flow trigger criteria
                  to ensure flows run only when necessary. Consider using entry conditions to limit
                  when record-triggered flows run.</p>
              </td>

              <td data-label="Prevention Technique" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e243 ">
                <p style="margin-bottom:0;">Review the cumulative impact of all automation (flows, processes, workflows,
                  triggers) that can run in the same transaction. Monitor and optimize the entire
                  automation chain.</p>
              </td>

            </tr>
            <tr class="">
              <td data-label="Problem" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e237 ">
                <p><strong>Bulk Data Loads</strong></p>
                <p>Record-triggered flows that run during bulk data imports or mass updates require
                  efficient processing of all records. Inefficient flows hit CPU limits during bulk
                  operations even if they work fine for individual records.</p>
                <p style="margin-bottom:0;"><strong>Example:</strong> A user imports 200 account records. The before-save
                  record-triggered flow performs multiple lookups and calculations for each
                  account.</p>
              </td>

              <td data-label="Solution" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e240 ">
                <p><strong>Optimize for Bulk Operations</strong></p>
                <ul>
                  <li>Use collection-based DML and queries</li>

                  <li>Consider after-save flows for non-critical operations (they run asynchronously
                    and have higher CPU limits)</li>

                  <li>Use Transform elements (Filter, Map, Sort) which operate on entire collections
                    more efficiently than loops</li>

                </ul>
                <p style="margin-bottom:0;">For more information, see <a href="https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_transform.htm&amp;release=264.0.0&amp;type=5" title="Select the flow resources for mapping and transforming source data to target data. You can use the Transform element in screen flows, autolaunched flows with no triggers, and record-triggered flows.">Transform Element</a>.</p>
              </td>

              <td data-label="Prevention Technique" class="slds-cell-wrap" style="vertical-align:top;" headers="d158466e243 ">
                <p style="margin-bottom:0;">Always assume record-triggered flows process multiple records simultaneously. Test
                  with bulk data loads (by using Data Loader or mass updates) before deploying to
                  production. If not properly designed, a flow that works perfectly for individual
                  records can fail during bulk operations if not properly designed.</p>
              </td>

            </tr>
          </tbody>
        </table>

### General Prevention Guidelines

- **Monitor flow performance:** Review Apex debug logs regularly to identify flows approaching CPU limits, even if they haven't failed yet. Regular monitoring helps you optimize flows before they cause production issues.
- **Test with realistic data:** Test flows with realistic data volumes to uncover performance issues before activation. Debug mode typically tests with one record, which doesn't reveal bulk operation issues.
- **Document optimization decisions:** Use element descriptions to note where you applied bulkification or other optimizations. This documentation helps future maintainers understand the design and prevents the accidental introduction of performance issues.
- **Start simple and optimize:** Build flows in small increments, testing performance at each step. Optimizing a working flow is easier than fixing a complex broken one.

## Identify CPU-Intensive Elements in a Flow

Use Apex debug logs to pinpoint which elements in your flow consume the most CPU time.

1. Go to **Setup** and enter Debug Logs in the Quick Find box.
2. Set up debug logging for the user who experiences the error, or run the flow in Debug mode.
3. Reproduce the error by running the flow.
4. Open the generated debug log.
5. Search for these key events in the debug log.
    
    - `FLOW_CREATE_INTERVIEW_BEGIN` - Shows when each flow starts
    - `FLOW_ELEMENT_LIMIT_USAGE` - Shows CPU time consumption for each flow element
    - `CUMULATIVE_LIMIT_USAGE` - Shows running totals of CPU time
6. Identify elements with high CPU time values.
    
    Common culprits include:
    
    - Loop elements with large collections.
    - Get Records elements with complex filters.
    - DML operations with multiple records (Create Records, Update Records, Delete Records).
    - Assignment elements with complex formulas.

You now know which elements are consuming the most CPU time. Use this information to apply targeted optimizations.

For more information about debug logs, see [Working with Logs in the Developer Console](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_system_log_console.htm).