Every developer needs debug code, because it’s the easiest way how to search for the issues in code. But with big Salesforce organisations, new issue arises during debugging. Salesforce allows only 2 MB of debug log. This limit can be easy reached when you have few triggers which are executed together. So how can you get your logs?

There are 2 solutions:

  1. First of them is to put in developer console list of triggers/classes which you want to debug – sometimes it doesn’t work correctly. Open your developer console, from the menu select Debug->Change debug log levels and add your trigger/class into ‘Class and Trigger Trace Overrides.
  2. The second, my favorite solution: Use debug logging level. Instead of using System.debug(‘debug text’) ; use in your code alternative

System.debug(Logginglevel.ERROR , ‘debug text’); This will say that this debug log should be shown in logging level ERROR.

Then change your log level filters:

  • Database : NONE
  • Workflow : NONE
  • Validation : NONE
  • Callouts : NONE
  • Apex Code : ERROR
  • Apex Profiling : NONE
  • Visualforce : NONE

Now you will have only your debugs in logs. With this trick you can debug lot of codes without getting log size reached error. Good luck with debugging :)