Apex Leftover Debug Statement
Why is this an issue?
System.debug() statements left in production code can:
Expose sensitive information: Debug output may reveal internal data structures or user information
Impact performance: While minimal, debug statements do consume CPU time
Clutter debug logs: Makes it harder to find relevant debugging information
Indicate incomplete code review: Debug statements often signal code that wasn't fully cleaned up
This rule detects System.debug() calls in non-test classes. Test classes are excluded since debug statements are often useful during test development.
Examples
Example of incorrect code:
public class AccountService {
public void processAccount(Account acc) {
System.debug('Processing account: ' + acc.Name); // Leftover debug
// Business logic
System.debug('Done processing'); // Leftover debug
}
}
Example of correct code:
public class AccountService {
public void processAccount(Account acc) {
// Business logic without debug statements
}
}
How can I fix violations?
This rule supports autofix, which removes the debug statements.
To fix manually:
Review each debug statement to ensure it's not providing important information
Remove the
System.debug()callsIf logging is needed for production monitoring, consider using a proper logging framework
Resources
