NexBlazers Logo
NexBlazers Learn • Build • Grow
Architecture & Apex

Apex CPU Time Limit Exceeded in 2027: Find the Real Culprit Across Flows, Triggers and Managed Packages

Written by NexBlazers Architecture Team November 24, 2026 14 min read Interactive

The data load fails at row 4,201. The error says acme.OppSyncTrigger: System.LimitException: Apex CPU time limit exceeded. Someone opens a ticket with the vendor, the vendor says "not us", and a week goes by. The name in that error is almost never the whole story.

CPU time is one budget shared by everything that runs in a transaction: your triggers, your Flows, validation rules and every installed package. The error names whoever happened to be running when the budget ran out, not whoever spent it. In this post you'll break and fix a real-looking transaction in the CPU Budget Lab, learn the four-step playbook for finding the true culprit in a debug log, and test yourself with a diagnosis quiz.

10,000 msSynchronous CPU limit
60,000 msAsynchronous CPU limit
1 budgetShared by your org and every package
0 msCounted for database or callout waiting
CPU Budget Lab

Who Gets Blamed vs Who Spent the Time

An Opportunity update runs through a before-save Flow, a custom Apex trigger, validation rules, a managed package trigger and an after-save Flow. Change the volume and apply fixes, and watch the budget.

Records in the transaction
Context
Fixes and settings
CPU used, in execution order
Breakdown by component
ComponentmsShare
Debug log (simplified)

                        

The millisecond costs are illustrative, chosen to show typical patterns. The rules they follow (one shared budget, the error names whoever is running at the limit, async gets 60 seconds) come from the Apex Developer Guide.

1. What Actually Counts Toward the 10 Seconds

The Execution Governors and Limits page sets the maximum CPU time on the Salesforce servers at 10,000 ms for synchronous transactions and 60,000 ms for asynchronous ones. CPU time covers all execution on the application servers in one transaction: the Apex that's running, plus anything it calls, such as package code and workflow. Salesforce's own Help article on coding efficiently to avoid the error lists triggered Apex, workflow rules, validation rule formulas and managed package code all drawing from the same budget. Flows count too: Trailhead's Avoid Flow Limits unit walks through an Apex class using 9 seconds and then calling a Flow that needs 2, which fails the whole transaction.

What doesn't count matters just as much. Time spent in the database for SOQL, SOSL and DML isn't counted, and neither is time spent waiting on callouts. A slow query makes the user wait, but it won't throw this error. Only server-side processing does: loops, string and JSON work, formula evaluation, Flow element processing and object creation. (The small amount of application-server CPU used to prepare DML does count, though Salesforce says it isn't expected to be significant.)

2. Why Managed Packages Get Blamed

Certified managed packages, the ones that passed AppExchange security review, get their own copy of most per-transaction limits. That's why a package's queries don't eat your 100 SOQL queries. But the Apex Developer Guide lists the exceptions, and CPU is one of them: heap size, maximum CPU time, maximum transaction time and the number of unique namespaces are shared across your org's code and every package.

So when the shared CPU budget runs out, the exception is thrown in whatever code unit is running at that moment. Salesforce's Account Engagement sync article describes it as almost always a "team effort" from several triggers, where the package that happens to be running gets named. Packages often run late in the save, after your own automation has already spent most of the budget, so they are frequently the last one in the room when the lights go out.

Architecture Note: Don't assume the opposite either. Packages can be the real culprit, especially on large records (Salesforce's own CPQ Help articles describe CPU errors on very large quotes). The point is to measure, not to guess. The playbook below works whichever way the evidence points.

3. The Four-Step Playbook

Step 1: Reproduce with the right log levels

Set a trace flag on the user who actually hits the error. For data loads and integrations, that's the integration user, not you. Use Apex Code at FINE or above, Workflow at FINE or above, and Apex Profiling on. Apex Code FINE logs ENTERING_MANAGED_PKG lines, so you can see when control passes into a package. Workflow covers Flows and processes, and at FINER it adds FLOW_BULK_ELEMENT_DETAIL lines that include each element's execution time. Apex Profiling writes the cumulative limit summary at the end.

Mind the size: the Debug Log docs cap each log at 20 MB, and larger logs lose older lines. If your log gets truncated, lower the categories you don't need (Database, Validation, System) rather than losing the lines you do.

Step 2: Follow the timestamps, not just the summary

Every log line starts with a clock time and an elapsed value in parentheses (nanoseconds since the transaction started). The fastest manual method is to find each CODE_UNIT_STARTED and CODE_UNIT_FINISHED pair, one per trigger, Flow or validation run, and subtract. The unit with the biggest gap is your first suspect, whatever the final error line says.

Treat the per-namespace LIMIT_USAGE_FOR_NS summaries with care. They're very useful for SOQL and DML, but because CPU is shared, the "Maximum CPU time" figure isn't a clean per-package bill. Elapsed time between code units is the more honest measure.

Step 3: Visualize it

Reading a 15 MB log by hand is slow. The free Apex Log Analyzer extension for VS Code (built by Certinia and featured on the Salesforce Developers blog) turns a log into a flame chart and call tree, showing where Flows and managed packages sit in the timeline. Wide bars are where the time went. To measure a suspect directly, wrap it in a CPU checkpoint:

Integer cpuBefore = Limits.getCpuTime();
OpportunityService.applyRegions(Trigger.new);
System.debug(LoggingLevel.INFO, 'applyRegions CPU ms: '
    + (Limits.getCpuTime() - cpuBefore)
    + ' | transaction so far: ' + Limits.getCpuTime()
    + ' of ' + Limits.getLimitCpuTime());

Step 4: Confirm the pattern in production

One log proves one transaction. To see whether it's a pattern, use production telemetry. With Event Monitoring, the Apex Execution event type records CPU_TIME, DB_TOTAL_TIME, the entry point and the execution context for each request. Comparing CPU_TIME with DB_TOTAL_TIME tells you whether a slow request is a code problem or a database problem. Scale Center and ApexGuru go a step further: ApexGuru uses runtime profiles to flag Apex hotspots and anti-patterns, ranked by how much real CPU they use in your org.

4. The Usual Culprits and Their Fixes

Nested loops that grow with the square of the batch. Code that's instant for one record can take seconds at 200, because every record scans every other record.

Before: every opportunity scans every account

// accounts: List<Account> queried once for all AccountIds in Trigger.new
for (Opportunity opp : (List<Opportunity>) Trigger.new) {
    for (Account acc : accounts) { // up to 200 x 200 = 40,000 checks
        if (acc.Id == opp.AccountId) {
            opp.Region__c = acc.Region__c;
        }
    }
}

After: one Map lookup per opportunity

Map<Id, Account> accountsById = new Map<Id, Account>(accounts);
for (Opportunity opp : (List<Opportunity>) Trigger.new) {
    Account acc = accountsById.get(opp.AccountId); // 200 lookups
    if (acc != null) {
        opp.Region__c = acc.Region__c;
    }
}
  • Recursion. An after-save Flow or trigger that updates the same records makes the save run again, triggers and all. Add a guard (track processed record IDs in a static set) and make sure updates only happen when a value really changes.
  • Flows doing too much. Use before-save Flows for same-record field updates, since they skip an extra save. Add entry criteria so the Flow runs only when relevant fields change. Keep Get Records and Update Records out of loops, and avoid looping over large collections.
  • Heavy processing in a loop. JSON serialization of big object graphs, repeated describe calls, string building and regex inside loops all burn CPU. Cache what you can outside the loop.
  • Too many automations on one object. Three Flows, two triggers and a package on Opportunity each look cheap alone. Consolidate to a clear order: one trigger framework, and a small number of well-scoped Flows.
  • Managed packages. Check the vendor's documentation for bypass or "skip during data load" settings, confirm you're on a current package version, and send the vendor a log that shows elapsed time per unit, not just the error line.

And when the work is genuinely large, move it out of the save. Queueable or Batch Apex runs in its own transaction with the 60-second asynchronous limit, and the user's save no longer waits for it. That's a design change, not a patch: an O(n²) loop is still O(n²) in a Batch job.

5. What's Different Heading into 2027

The Winter '27 release raised the Apex heap limits: from 6 MB to 10 MB for synchronous transactions and from 12 MB to 25 MB for asynchronous ones, as covered in Salesforce's Winter '27 architect highlights. The CPU limit didn't change: it's still 10 and 60 seconds.

That has a practical side effect. Code that used to fail on heap first, such as loading tens of thousands of rows into memory or building a large JSON payload, can now get further, and then hit the CPU wall instead. If your team chunked work mainly to stay under the old heap ceiling, re-test CPU before you remove the chunking.

The same release extended elastic limits for asynchronous Apex jobs (beta). Elastic limits are about how many async jobs an org can enqueue in a rolling 24 hours. They don't give any single transaction more CPU, so they're not a fix for this error.

Diagnose it

Predict the Culprit

Five real-world scenarios. Pick an answer to see the rule behind it.

Cheat Sheet

QuestionAnswer
Limit?10,000 ms sync, 60,000 ms async. Unchanged in Winter '27.
Shared with packages?Yes. CPU, heap, transaction time and namespace count are shared, even with certified packages.
What counts?Apex, Flows, workflow, validation formulas, package code. Not database time or callout waits.
Who does the error name?Whoever was running when the budget ran out. Not necessarily the biggest spender.
Log levels?Apex Code FINE+, Workflow FINE+ (FINER for Flow element timings), Apex Profiling on.
Best evidence?Elapsed time between CODE_UNIT_STARTED and CODE_UNIT_FINISHED, or a flame chart.
At scale?Event Monitoring Apex Execution (CPU_TIME vs DB_TOTAL_TIME), Scale Center and ApexGuru.
Top fixes?Maps instead of nested loops, recursion guards, Flow entry criteria, fewer automations per object, async for big work.
Keep learning

Official Resources

Straight from Salesforce: the docs this article is based on.

Chasing CPU timeouts across Flows, triggers and packages?

Book a performance review with our architects to find the real culprit and fix the automation design.

Book Performance Review

All information in this article was collected from publicly available resources, including official Salesforce documentation.