1

What is the Difference between the Maximum CPU time on the Salesforce servers(10 second) and maximum execution time for each apex transaction (10 minute) ?

1

1 Answer 1

4

Complete details about the apex transaction is given in the dev guide here.

An Apex transaction represents a set of operations that are executed as a single unit. All DML operations in a transaction either complete successfully, or if an error occurs in one operation, the entire transaction is rolled back and no data is committed to the database. The boundary of a transaction can be a trigger, a class method, an anonymous block of code, a Visualforce page, or a custom Web service method.

CPU Time reference can be found in the dev guide here.

CPU time is calculated for all executions on the Salesforce application servers occurring in one Apex transaction. CPU time is calculated for the executing Apex code, and for any processes that are called from this code, such as package code and workflows. CPU time is private for a transaction and is isolated from other transactions. Operations that don’t consume application server CPU time aren’t counted toward CPU time. For example, the portion of execution time spent in the database for DML, SOQL, and SOSL isn’t counted, nor is waiting time for Apex callouts.

Consider a record update invoking an apex trigger execution. Now, this trigger execution will run in a single apex transaction and will time out if it doesn't complete execution within 10 minutes. However, within this transaction, there could be few SOQL & DML executions (*say 10 SOQL query and 2 DML *) or execution of validation rules, flows etc. The time spent in performing these SOQL & DML (or rules, flows etc.) will be counted towards the transaction execution time, but not in the CPU usage time. CPU usage time is calculated only based on the time spent while executing the current apex code (or the apex code called by current code or anything within the control of developer (code) that uses application server CPU). During DML execution there will be other actions performed like record-locking or waiting for lock to be released on records being processed or apex code compilation (that cannot be controlled by the developer). All this time will not be counted towards the CPU utilization time.

Check out this old article, if interested.

2
  • 4
    Please don't use images when you can copy text. This makes it inaccessible to those with vision problems (e.g. need a screen reader).
    – sfdcfox
    Oct 31, 2020 at 14:32
  • Good point @sfdcfox. Had not thought about this. Updated my answer with text.
    – arut
    Oct 31, 2020 at 16:35

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