8

I'm using developer console log to see all my debug logs but it cuts off my log after 1920 characters

How do I fix that? and even I have tried download the log and open in a notepad++ but still I see the cut off

CurrencyIsoCode=USD}), ...} <<<<<

13

This is a feature (although in this case you may not view it as such, understandably) of the built in toString on apex collection types. The idea being that since the debug log has a maximum size debugging a single large collection would truncate other potentially valuable log lines.

System.debug however does no such truncation, so any string you pass to it should be displayed accurately in your logs.

As BobTheBuilder mentioned you can serialize your collection to JSON, as this creates a full-length string which you can then pass to System.debug and get the full un-abbreviated value. You could also iterate over your collection to build a large string yourself and debug that. Basically as long as you don't rely on the toString implementation of system types you're free to get log whatever you like.

6

Wrapping your list variable with JSON.serialize(your_list_here) should solve your issue.

I.e.: System.debug(JSON.serialize(list_var));

  • 1
    This does not appear to be working for me anymore, anyone else have truncation even with the JSON.serialize trick? – Daniel Sokolowski Apr 15 at 13:42
  • @DanielSokolowski did you find anything on it? – apple123 Apr 23 at 18:15
  • @apple123 I ended up creating a small wrapper class for whenever I need to workaround this limit. – – Daniel Sokolowski Apr 23 at 18:51
  • @DanielSokolowski that sounds interesting, would you be kind enough to share a few details on it? or a little snippet of the code? – apple123 Apr 23 at 22:18
  • @apple123, yes of course, see my answer below (or above). – Daniel Sokolowski Apr 24 at 13:11
5

The JSON.serialize(...) trick no longer works, if one needs un-truncated messages following wrapper class is what I use, I just paste it as helper method at bottom of the apex class in those situations I need un-trunctated logs:

public void mDebugUntruncated(String sMsg) {
    for (Integer i = 0; i < sMsg.length(); i=i+300) {
        Integer iEffectiveEnd = (i+300 > (sMsg.length()-1) ? sMsg.length()-1 : i+300);
        System.debug(sMsg.substring(i,iEffectiveEnd));
    }
}

Then for example you would call it as you would call it with:

this.mDebugUntruncated('=== QV_QuickLinkListLoader.getContent(...):`JSON.serialize(sJSONRequest)=' + JSON.serialize(sJSONRequest) +'`');

un-trunctated salesforce debug message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.