13

For the longest time I have been using System.debug(JSON.Serialize(o)) to output objects to the debug log for troubleshooting purposes. This has worked up until my most recent project. Even existing code seems to be having this behavior.

I've tested API versions 41-45 with no luck. The actual line of code I'm using is:

system.debug(json.serialize(accountsToInsert)); // This is a map

I have also tried:

system.debug(json.serialize(accountsToInsert.get(Key)));

AND

Account test = accountsToInsert.get(Key);
system.debug(json.serialize(test));

The code is called from a method defined in a VF page action attribute.

Is this just a thing that we have to live with now? Is there another way to get a full look into the state of an object at run time?

7

2 Answers 2

19

Unfortunately, since Spring'19 in order to improve performance, Salesforce changed a way how long strings are shown in the Developers Console.

Now strings are now truncated at 512 characters in the Developer Console’s Log Inspector

In order to retrieve full log, it is needed to use Open Raw Log in Developers Console menu.

Release notes with more information – https://releasenotes.docs.salesforce.com/en-us/spring19/release-notes/rn_forcecom_developer_console.htm

Some Suggestions:

  • The Apex Replay Debugger is a powerful debugging tool - Note Seems to have issues with very large debug logs.
  • Checkpoints can be used to inspect objects at given points in code using the developer console.
  • Apex Interactive Debugger - This has become my personal favorite debugging tool.
3
  • 3
    For completeness, I combined the other answers into a single post. I'm heading down the path of the replay debugger as my solution.
    – gNerb
    Mar 27, 2019 at 15:43
  • thanks @gNerb. Personally sometimes I use apex snippet to create a Document with given body if it is a size of 2-3mb
    – kurunve
    Mar 27, 2019 at 15:53
  • 1
    Updated with references to the Apex Interactive Debugger since this question seems to be a popular one.
    – gNerb
    May 7, 2020 at 16:07
13

I always recommend using Checkpoints; this gives you an easy way to inspect the entire heap (memory). You can learn more about this in the trailhead Inspect Objects at Checkpoints. Simply open the Developer Console, open the class you want to inspect (e.g. your controller), and click on the left-side gutter for the point you'd like to set the checkpoint. The checkpoints will appear in the Checkpoints tab in the Developer Console when you perform the action.

2
  • 1
    This is great information, but I think that Karune has the actual answer. +1 though.
    – gNerb
    Mar 27, 2019 at 15:24
  • Does this work for apex that gets invoked from UI? because after my ui is finished rendering I dont get details loaded in lthe panel left side to checkpoint location Jun 2 at 7:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .