Loading
Upcoming Mandatory Changes to Public Key Infrastructure (PKI)Read More
Salesforce Enforces New Security Requirements in Summer 2026Read More

Error "Apex CPU time limit exceeded" when creating Work Orders in Salesforce Field Service

Publish Date: Jun 25, 2026
Description

Description

Salesforce Field Service allows you to automate Work Order creation using flows. If your flow contains custom Apex logic, complex automation, or processes large record sets, the flow may exceed Salesforce's CPU time limit and fail with an `Apex CPU time limit exceeded` error. This prevents Work Orders from being created and disrupts your operational workflow.

Symptoms

You experience one or more of the following:

- Work Order creation fails with the error message `System.LimitException: Apex CPU time limit exceeded`.
- The error occurs intermittently, often when creating multiple Work Orders in a batch or when processing large related record sets.
- The error does not occur when creating a single Work Order but appears under higher load.
- Debug logs show CPU time consumption approaching or exceeding 10,000 milliseconds (10 seconds).

Cause

When you create a Work Order through a flow in Salesforce Field Service, the flow executes within a single transaction. Salesforce enforces a CPU time limit of 10 seconds for synchronous transactions initiated from the user interface. If the flow contains custom Apex logic, complex decision trees, loops, or calls to external systems, the combined processing time can exceed this limit, triggering the error.

Common contributors to CPU time consumption in Work Order creation flows include:

- Apex actions or invocable Apex methods with inefficient queries or loops
- Multiple nested decision elements or loops processing large record sets
- Formula field evaluations on related records
- Synchronous callouts to external systems
- Unoptimized SOQL queries without proper indexing or filtering

 

Resolution

Resolution

Step 1: Enable Debug Logging and Identify the Bottleneck

Enable a debug trace flag for your user and re-run the Work Order creation flow. Review the debug log to identify which Apex actions, decisions, or queries consume the most CPU time. Look for repeated queries in loops or inefficient SOQL statements.

Step 2: Optimize Apex Logic

If the flow calls custom Apex:

- Refactor loops to use bulk operations instead of processing records one at a time.
- Move queries outside loops; use a single query with proper filtering and store results in a variable.
- Remove unnecessary field selections; query only the fields your logic requires.
- Avoid calling external APIs synchronously; use `@future` or Queueable Apex to defer the callout to an asynchronous context.

Step 3: Simplify Flow Logic

- Reduce the number of nested decision elements; combine conditions where possible.
- Avoid loops that iterate over large record sets; use batch processing or asynchronous subflows instead.
- Remove unused formula field evaluations or move them to a separate, asynchronous flow.

Step 4: Convert to Asynchronous Processing

If the Work Order creation does not require an immediate response to the user, convert the flow to run asynchronously:

- (unverified-control) Set the flow's trigger to run asynchronously, or wrap the heavy logic in a scheduled action or subflow that runs after the initial transaction completes.
- Asynchronous transactions have a 60-second CPU time limit, providing more headroom for complex automation.

Step 5: Adjust Batch Size or Record Limits

If the flow processes multiple Work Orders in a batch:

- Reduce the number of records processed per flow execution.
- Implement pagination or chunking logic to split large batches into smaller transactions.

 

Additional Resources

Known Limitations

- **Asynchronous conversion trade-off:** Converting a flow to asynchronous processing increases the CPU time limit to 60 seconds but introduces latency — the Work Order creation will not complete immediately, and the user will not see the result in real time.
- **Batch size vs. CPU time:** Reducing batch size prevents CPU limit errors but may require more flow executions, increasing API call counts and potentially hitting other governor limits (e.g., API call limits per 24 hours).
- **Debug logging overhead:** Enabling debug logging increases CPU time consumption during troubleshooting; disable trace flags before deploying to production to avoid masking the true CPU cost of your flow.

 

Knowledge Article Number

005386934

 
Loading
Salesforce Help | Article