Sunday 1 May 2011

MAXIMUM DEBUG LOG SIZE REACHED


"I would love to lift the limits up, but salesforce won't give me the source code" :)


At times there could be a situation where Scripts statements are more and we hit the limit of "Debug Log Size" and we get the message "MAXIMUM DEBUG LOG SIZE REACHED" .One way to overcome this is to set filters for the debug logs as mentioned below :



Go to Monitoring-->DebugLogs-->Filters (set all the Filters to None expect for the apex Code)











In this way we restrict the log to show only the error part. But say u still want to get some other Information(Like HeapSize,State of different variables and statistics etc) from the Debug logs irrespective of the log filter.In such cases email messages help ...Just put the Email code at the Line  No where you want to track the code and then put the excepted results in the Subject or Text body of the email and send an Email to some one of your choice(probably in most cases the same person). So now the email tracks everything related to code :Here is an snippet of code which tries to get different values returned for limits .

I was working on batch apex and the size of debug log was tooooooo high...So to keep track of some governor limits and to know the status and state of different variables in the batch i used email concept.






Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
String[] toAddresses = new String[] {'chaitanya_cvm@yahoo.com'};         
mail.setToAddresses(toAddresses);                    
mail.setSubject('At Post Process limit queres::'+ limits.getScriptStatements ()+ 'No left::'+limits.getLimitScriptStatements () +'heapsize::'+limits.getHeapSize ()+'left'+limits.getLimitHeapSize());                   
mail.setPlainTextBody("Get Error Message:"+e.getmessage());                 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

            
So above mail just sends me the list of limits used and available limits etc



Note :Make sure to send emails to "Internal " users only so as to make sure we don't hit daily email limit. And most importantly remember to remove this code after unit testing is done :)

Happy Debugging!!!

No comments:

Post a Comment