Trick for real-time debugging in salesforce

As you know provides a simple but powerful tool for debugging your application, this tool is pretty cool and helpful if you’re working with a small business application and a simple business rules. But from the moment when your application is going to be an enterprise application, all is changed. From this moment the platform limitation is your trouble and you need a workarounds, tricks and hacks. There are I’d like to present a few tricks which might be useful for debugging.

The most applications which I developed has a complex and pretty tricky workflow. As a result in the most cases the limitation of 2 Mb per log was reached on the average 25-30% of whole code and the rest part of log was reduced. It’s going to be a real trouble when you’re working with Batch apex or complex triggers which might be cause of invocation of another trigger. This case you do not see the most part of the log.

The most common way for preventing a hitting this limit is changing the log level in developer console by the following way Debug → Change Log Levels

So, as you can see in the configuration of logs level the default log level was set to ERROR for each event type exclude “Apex Code”. By this action you got the ability of having the short and very informative logs which were defined by you, without ant buzz system messages and debug messages of your colleagues.

Now you need to start using logging level definition in your code:

System.debug(LoggingLevel.WARN, 'your log msg');

This simple trick allows you to reduce logs in a few times and more and it might be very helpful in case when you’re struggling against a huge logs.