Below is information on how to troubleshoot errors when hitting Salesforce's governor limits.
Error: Apex CPU time limit exceeded. An unexpected error has occurred. Your solution provider has been notified. (ApexPage).
Situation 1: I am having an issue posting a billing. Upon clicking the Post button, it will run for a while and throw the error.
Situation 2: We received the error when trying to batch pay/post 50 checks.
An Apex Timeout Exception effectively means that too much Apex Code (or process builder flows or both) is attempting to execute and is exceeding the time limit allocated by Salesforce. Salesforce imposes a limit on the CPU usage that can be consumed in a given execution context, which is approximately 10 seconds. This article explains the concept in more detail. In a nutshell, too much processing is attempting to occur between our code and some other code and is taking too much time.
You might assume this is an Accounting Seed error because it says AcctSeed in the error message but this is not exactly the case. We have performed extensive stress tests on our app and ensured that our code adheres to best practices and is tuned for performance. In our tests, all our processes (i.e. posting a billing, closing an accounting period) use 1.2 seconds or less of CPU time. What is probably using up most of the CPU time is other Apex Code or Process Builder flows.
This limit is enforced on all code involved in a certain execution without regard to whether the code exists in:
- Accounting Seed Financial Suite’s managed package, or
- Another ISV's managed package that interacts with Accounting Seed’s components, or
- Custom code developed by your company
- Process Builder: If you have a process builder on the Billing object, disable some of the process builder flows or move its logic to code which executes using an asynchronous approach.
- Another Managed Package Involved: If code from another managed package (i.e. Rollup Helper) is taking part in a transaction such as Posting a Billing you will need to contact the authors of the that managed package.
- Custom Code: If you have custom code (i.e. trigger) you will need to contact your developer or responsible organization to refactor your current custom solutions to ensure you do not exceed the CPU time limit. This article includes suggested approaches to mitigate the CPU time limit exceeded issue.
Workarounds if the error is caused by a button like Create & Post
- Use just the Create button rather than the Create and Post button. This will only perform the Pay function and may assist in preventing the Apex CPU time limit exceeded error.
- Work with a reduced subset of payables for paying a batch. You may need to experiment with this to determine the right batch size that can be supported.
Resolve the Issue
- Use @future calls and asynchronous processing to move non-critical business logic out of triggers and/or Process Builder processes.
- Convert Process Builder processes to Apex Triggers if possible.
- Ensure Apex Code is written efficiently
- Follow Apex best practices for Triggers and Bulk processing
- What To Do If You Keep Exceeding Apex CPU Time Limit?
- Apex CPU time limit exceeded Errors
- Apex CPU time limit exceeded - Please help!
Article is closed for comments.