+ Start a Discussion
sfadm sfadmsfadm sfadm 

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

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 stacktrace 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.

Please advise how to realize which is the method that is trowing such error and is consuming the entire cpu time.

Please advise how to avoid such error because I really need to find a solution as every time I try to deploy on production I receive such error message:

Apex CPU time limit exceeded and An unexpected error has occurred. Your development organization has been notified.
 
Best Answer chosen by sfadm sfadm
jigarshahjigarshah
Issue Details & Resolution
Salesforce enforces a limit on the CPU time taken to execute a transaction. Hence, if there is a long running transaction which is synchronous and violates the max CPU time limit for a transaction, you will recieve a Apex CPU Time Limit Exceeded error.

The general thumb rule for resolving Apex CPU time limit exceeded error is to search for long running synchronous transactions and check if they can be optimized for optimal resource usage or can be converted into asynchronously running transactions i.e. using a Batch Job or other async techniques.

The following article provides the details around the cause and best practices for addressing the Apex CPU Time Limit Exceeded issue - https://help.salesforce.com/articleView?id=000232681&language=en_US&type=1

Identifying Performance Bottleneck using Developer Console
You can leverage the Developer Console to identify the proesses in the transaction that take more time to complete. This blog from Salesforce helps you understand how to track the performance to identify long running transactions using the Performance Profiling feature within your Developer Console - https://developer.salesforce.com/blogs/engineering/2013/05/force-com-performance-profiling-using-the-developer-console.html