0

When I try to deploy on my production environment I receive the following error message:

Apex CPU time limit exceeded and An unexpected error has occurred. Your development organization has been notified.

The last method in stack trace where the error happens is my custom method.

I presume that the error is due to the fact that some of the other methods is taking considerable amount of time to be executed.

How can I tell which method is throwing this error? Is there a method to track CPU usage?

  • One of your test methods is taking an inordinate amount of time to complete. This can happen for a variety of reasons. Most often, I have seen it happen due to a test method that inserts a larger-than-normal number of objects in a very trigger-heavy Salesforce instance. It's difficult to debug without seeing the specific code that is failing. – David Reed Jan 30 '18 at 23:30
2

One of your test methods is taking an inordinate amount of time to complete. This can happen for a variety of reasons. Most often, I have seen it happen due to a test method that inserts a larger-than-normal number of objects in a very trigger-heavy Salesforce instance.

To troubleshoot this issue, you'll first need to determine which test methods are failing. Run your tests with the Developer Console active, and utilize the log inspection capabilities to find areas that are taking too much time. Then, you can address any performance problems, like inserting too many objects in a test context or executing inefficient SOQL queries.

The CPU time limit is cumulative over a transaction, so it's not necessarily a single piece of code consuming the entire limit. You need to be looking for any areas that are taking a large portion of the 10 second CPU time allotment. Remember that each test method gets its own transaction and 10 second time span for execution.

  • 2
    It's also possible that some logic in the Apex the OP has deployed contains logic that leads to an infinite loop under the conditions in prod. For example A triggers B and then B triggers A back. Or something in prod that wasn't in the sandbox results in an Apex loop failing to ever find an exit condition. – Charles T Jan 31 '18 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.