Loading
Scalability
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          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());
          
           
          Loading
          Salesforce Help | Article