Our managed package runs into CPU timeouts in a customer production which we tried to reproduce in our DE packaging org.

We added some of the custom workflows, formulas and rollups but where unable to provoke a CPU timeout in the DE org.

When comparing the Dev Console timeline from failing Customer org

enter image description here

and our DE org

enter image description here

I can only draw the following conclusion. Executing code is slower in the DE org (as production orgs are faster) but the root cause for the timeout is the long waiting periods between the actual execution.

Can someone explain those lags and how I can influence them?

Note: The repeated blocks on the timeline don't show any kind of loop! Its a huge amount of records which is handled in 200 record chunks by triggers.

  • 4
    No, DE and EE run on the same hardware (except DE has certain code-based limits, like queueable chains). However, did you check the logging levels of each org for a comparison? You're probably running into other limits because your logging level is set too high in one org versus the other. I had that happen recently where I couldn't save contacts in our sandbox, but all other users could. I had to dial down the logging levels to allow my user to save. – sfdcfox May 1 '15 at 1:20
  • I decreased all log levels to Warn and got the same CPU timeout. But anyway...good to know that this sometimes helps. – Robert Sösemann May 4 '15 at 6:49
  • Going little offtrack, May i ask you if there is any way to centrally control the logging levels in salesforce apex like we have in Log4j in Java. Example - For production, only error statements are logged and for developer sandboxes, all statements above debug are logged? I did not come across any way. – Dave May 22 '15 at 1:56
  • 1
    It might be an issue around when Salesforce actually enforces the Maximum CPU time limit. In Debug logs still measuring code statements and not CPU time I could push around 50% past the stated CPU limit without it being enforced. The limits are likely enforced periodically during execution. Production may be stricter in enforcing them or they may be enforced during the increased lag time you are observing, – Daniel Ballinger May 23 '15 at 9:50
  • 1
    @Dave please post that as a separate new question, going offtrack usually doesn't lead to a meaningful response and confuses other readers. – Samuel De Rycke May 23 '15 at 17:52

Here are reasons why do you see waiting lags OR gaps in your graph:

  • Log levels not specific enough:

    If your debug log level filters aren’t set to the appropriate levels, the Developer Console will automatically filter out finer-level events, making it sometimes appear as if there were gaps in execution. This is remedied by setting your log levels appropriately.

  • Log file truncation:

There is a maximum log limit of 2MB per log file. When the limit is hit, detailed log lines are removed, which can result in what looks like gaps in the log. The log lines can be removed from any location, not just the start of the debug log. Note that when lines are removed due to the log file limit, they are removed in ENTRY / EXIT pairs. For example, the lines for a SYSTEM_METHOD_ENTRY and SYSTEM_METHOD_EXIT might both get removed, in order to keep the log view consistent. An example of this sort of gap might look like:

08:37:13.187 (1187280618)|CONSTRUCTOR_EXIT|[984]|01p|(ApexPages.StandardSetController)
08:37:13.620 (1620485725)|METHOD_EXIT|[5181]|01p|CartDetailViewController.searchCartLineItems()

Whereas the actual complete log without truncation would look like:

08:37:13.187 (1187280618)|CONSTRUCTOR_EXIT|[984]|01p|(ApexPages.StandardSetController) 08:37:13.187 (1187311551)|SYSTEM_METHOD_ENTRY|[993]|ApexPages.StandardSetController.cancel() 08:37:13.620 (1620440718)|SYSTEM_METHOD_EXIT|[993]|ApexPages.StandardSetController.cancel() 08:37:13.620 (1620485725)|METHOD_EXIT|[5181]|01p|CartDetailViewController.searchCartLineItems()

Apex component initialization cost in Visualforce pages: Using Apex properties or methods in Visualforce pages can sometimes hide the time taken for the component initialization code. For example, if you had a Visualforce component that called getParamValue() in the Apex controller via the debug log would not catch the initialization cost of .

  • Static Apex methods:

Calling static Apex methods will reference the static method in a different class, which might result in a cache miss and thus an extra compilation cost that will not be tracked in the debug log. For example, if you defined the following:

public class ClassA {
    public void call() {

public class ClassB {
    public static void staticCall() {}

and created an instance of ClassA and called call():

ClassA obj = new ClassA();

the call to the static ClassB method staticCall() might reflect a gap in the debug logs.

  • Salesforce Apex processing issues:

In some scenarios, things like extra compilation cost (perhaps due to converting a large amount of Apex code into bytecode) or a garbage collection sweep can result in a gap in the debug log.

All of these issues can cause gaps in the debug log, and are not indicative of any performance problems by themselves. Keep these in mind when reviewing your debug logs.

Authoritative reference: https://developer.salesforce.com/page/Troubleshooting_Apex_Performance_Problems

Here is how you can resolve Maximum CPU time issue:

  • Set the log level finest and get the complete graph of of execution
  • Identify which code bock is taking maximum time
  • optimize that code block
  • repeat this process till your code works

Generally this type of issue come due to heavy data in customer org. You will have think about optimizing your code or process those bulk records in asynchronous way

  • Very helpful, but it does not explain how I can solve my original problem that code times out in a fast customer org, while I am unable to reproduce this in my DE packaging org. I now understand what in general causes such gaps, but how can I find out what is causing them at this customer instance? Without understanding this I cannot help my customer. – Robert Sösemann May 26 '15 at 13:04
  • updated the answer... – AtulRajguru9 May 27 '15 at 5:07

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.