Salesforce Developer Console: How to view untruncated System.debug() output

Since the Salesforce Spring ‘19 release, string values in Apex logs viewed in the Developer Console have been truncated at 512 characters. This helps improve performance, but can be frustrating when you’re trying to see large log outputs such as the result of a SOQL query.

Happily, there are still a number of ways to see complete string values, and this article shows you how:

Open the raw log in the Developer Console

A raw log is just the plain-text version of the standard log.

To open a raw log in the Developer Console:

  1. Right-click on the desired log in the “Logs” list at the bottom of the Developer Console.
  2. From the list of options, select “Open Raw Log”.
Right-click on the log and select "Open Raw Log"
The raw log is a plain-text view which doesn't truncate strings

The upside of using raw logs is that strings are never truncated, so you will always see the full output. However, it can be harder to find the output of System.debug() statements because there is no option to filter or select the “Debug Only” checkbox when using raw logs.

Use JSON.serializePretty() to view objects

Just like JSON.serialize(), JSON.serializePretty() will convert Apex objects into a JSON string. However, JSON.serializePretty() also inserts some formatting, including new line characters (\n), which result in the structure of the object being logged out over multiple lines.

This is particularly useful for viewing SObject records, lists, maps, and the results of SOQL queries.

    Select FirstName, LastName, Account.Name
    From Contact
    Where Id = :cont.Id
Output of SOQL query using JSON.serializePretty()

Break up long strings into multiple chunks using a utility method

As mentioned earlier, new line characters (\n) will cause System.debug() to start printing on a new row in the Developer Console log.

Inserting new line characters into a long string at spaced intervals (under the truncation limit) will ensure that the whole message gets printed out over multiple lines.

The following code shows a utility method to achieve this:

public static void debugLongString(String longString) {
	// Create a regex group for every 250 character chunk of the string
	Pattern chunksPattern = Pattern.compile('(.{250})');
	// Add a newline character to the end of every group
	longString = chunksPattern.matcher(longString).replaceAll('$1\n');
	// New lines characters will cause System.debug() to print out
	// over multiple lines in the Developer Console
The debugLongStrings() method chops up a long string into several lines.