Effective variable debugging

Effective variable debugging: avoiding truncation

When you use System.debug() to display values of lists or big objects you usually see that the output is truncated:

When you use System.debug() to display values of lists or big objects you usually see that the output is truncated:

Don't do this
System.debug([SELECT Id, Name FROM Account LIMIT 100]);
bash
10:05:46:011 USER_DEBUG [1]|DEBUG|(Account:{Id=0010Y00001BmjXlQAJ, Name=JP Community Users},
Account:{Id=0010Y00001BqMUMQA3, Name=My Account #1}, Account:{Id=0010Y000016unWHQAY, Name=Customers},
Account:{Id=0010Y000016uofsQAA, Name=CommunityUsers}, Account:{Id=0010Y000016unWnQAI, Name=Partne

You can simply use JSON.serializePretty() method to see the full content of debugged variable:

Do this
System.debug(JSON.serializePretty([SELECT Id, Name FROM Account LIMIT 100]));
json
09:05:46.1 (47092646)|USER_DEBUG|[3]|DEBUG|[ {
  "attributes" : {
    "type" : "Account",
    "url" : "/services/data/v59.0/sobjects/Account/0010Y00001BmjXlQAJ"
  },
  "Id" : "0010Y00001BmjXlQAJ",
  "Name" : "JP Community Users"
}

Transcribed by hand from the original slide. Plain-text version of the whole catalog