function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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?

Best Answer chosen by Zuinglio Lopes Ribeiro Júnior
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:

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: