Debug statement left in production code

ID

apex.performance.avoid_debug

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Logging

Language

Apex

Description

Reports a System.debug call outside a test class that passes no LoggingLevel. A call that names its level is deliberate operational logging and is not reported.

Rationale

A debug statement costs CPU time whether or not anyone is collecting a log, because the platform evaluates its argument: a concatenation, a JSON.serialize of a record list or a loop variable is built on every iteration and then usually discarded. In a trigger running over a 200-record batch that is real time out of the 10-second synchronous budget. The text also lands in the debug log, which is where field values leave the transaction and become readable by anyone with log access.

The following code illustrates the pattern detected by this rule:

public class RenewalService {

    public void run(List<Account> accts) {
        // FLAGGED: Debug statement left in production code
        System.debug('running for ' + accts.size() + ' accounts');
        for (Account a : accts) {
            // FLAGGED: Debug statement left in production code
            System.debug(JSON.serialize(a));
            System.debug(LoggingLevel.FINE, a.Id);
        }
    }
}

Remediation

Remove the statements that were left from debugging. Where the logging is genuinely operational, pass an explicit LoggingLevel - that also states how important the line is - and avoid building the message eagerly: log an id rather than a serialized record.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved