From b3fa087d52e0f07e12bbe62ec1180a7b75d8ebec Mon Sep 17 00:00:00 2001 From: Daniel Ballinger Date: Wed, 25 Mar 2026 14:47:53 +1300 Subject: [PATCH] There is a misconception that _all_ system.debug statements need to be removed from the codebase before reaching production. This is really only an issue in main/hot code paths. Debug statements used sparingly and for exceptional paths are still valuable and won't significantly impact performance. A logging framework may add significantly more overhead than a debug statement. --- skills/generating-apex/SKILL.md | 2 +- skills/generating-apex/references/anti-patterns.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/skills/generating-apex/SKILL.md b/skills/generating-apex/SKILL.md index fd32d6c..dd3c338 100644 --- a/skills/generating-apex/SKILL.md +++ b/skills/generating-apex/SKILL.md @@ -91,7 +91,7 @@ If any constraint would be violated in generated code, **stop and explain the pr | Use Apex-native collections (`List`, `Map`, `Set`) rather than Java types | Prevent compile errors | | Verify methods exist in Apex before use | Prevent reliance on non-existent APIs | | Use `Assert` class instead of `System.assert*` in test classes | Legacy `System.assert`, `System.assertEquals`, `System.assertNotEquals` are deprecated; use `Assert.areEqual`, `Assert.isTrue`, `Assert.fail`, etc. | -| No `System.debug()` in production code | Debug statements pollute logs and waste CPU; use a logging framework or Custom Metadata–controlled logger instead | +| Avoid `System.debug()` in main code paths | Debug statements that concatenate variables into the string consume CPU regardless of logging being enabled; use a logging framework or Custom Metadata–controlled logger instead if required on main code paths | | Never use `@future` methods | Use Queueable with `System.Finalizer` for all async work; `@future` cannot be called from Batch, cannot chain, and cannot accept non-primitive types | ### Bulkification & Governor Limits diff --git a/skills/generating-apex/references/anti-patterns.md b/skills/generating-apex/references/anti-patterns.md index ba91a3b..4e573d1 100644 --- a/skills/generating-apex/references/anti-patterns.md +++ b/skills/generating-apex/references/anti-patterns.md @@ -30,7 +30,7 @@ These patterns indicate poor code quality and should be refactored. | **Multiple triggers on object** | Unpredictable execution order | Single trigger + Trigger Actions Framework | | **Generic `Exception` only** | Masks specific errors | Catch specific exceptions first | | **No trigger bypass flag** | Can't disable for data loads | Add Custom Setting bypass | -| **`System.debug()` everywhere** | Performance impact, clutters logs | Use logging framework with levels | +| **`System.debug()` in main code paths** | Performance impact from concatenating variables, even when logs are disabled | Use logging framework with levels | | **Unnecessary `isEmpty()` before DML** | Wastes CPU | Remove - DML handles empty lists | | **`!= false` comparisons** | Confusing double negative | Use `== true` or just the boolean | | **God Class** | Single class does everything | Split into Service/Selector/Domain |