+ Start a Discussion
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior 

Does System.debug count against Salesforce execution limits?

Hello folks,

Few time ago I was debugging a code and I noticed that using System.debug to put a Map in the log increased the CPU time.

That happened because I was debugging or even when I am not it count against Salesforce limits?

Regards
Best Answer chosen by Zuinglio Lopes Ribeiro Júnior
bob_buzzardbob_buzzard
Debug statements will count against the CPU limits, as that is purely calculating the length of time that the code spends in your methods.

One way to avoid this is to make the debug statements configurable, such as:
 
if (DEBUGGING)
{
   System.debug('...');
}

where DEBUGGING is a static variable or generated from a custom setting.  This would allow you turn off debugging in production, which can save a considerable amount of time if you are producing a lot of debug.

There's some analysis from my fellow MVP Simon Lawrence over on stack exchanges, which shows how much of a difference this can make:

http://salesforce.stackexchange.com/questions/41063/writing-too-much-to-debug-log-would-affect-apex-trigger-or-visualforce-page-perf