Loading
Scalability
ApexGuru Antipattern: Expensive Debug Statements

ApexGuru Antipattern: Expensive Debug Statements

Overusing System.debug() slows down execution, especially in production environments. Writing large amounts of data to logs increases the execution time and affects performance. Plus, the logs fill, making it harder to identify important issues.

Scope

Detection and recommendation

Detection Example

apex
  System.debug('Heap Size: ' + Limits.getHeapSize());

Recommendation

To make sure that expensive operations aren’t evaluated unless necessary, perform a conditional check before invoking the call. Minimize debug statements in production code. Use conditional checks before invoking expensive calls, especially if the debug statement involves expensive computations such as Limits.getHeapSize.

apex
// Commenting out the debug log in production environments 
// System.debug('Heap Size: ' + Limits.getHeapSize());
 
正在載入
Salesforce Help | Article