mirror of
https://github.com/forcedotcom/afv-library.git
synced 2026-08-08 00:10:29 +08:00
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.
This commit is contained in:
parent
aef6597b91
commit
b3fa087d52
@ -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
|
||||
|
||||
@ -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 |
|
||||
|
||||
Loading…
Reference in New Issue
Block a user