6

I would need to print all the elements of a list so to be able to copy them (CTRL+C) . In Debug Log , I can see only the first 10, or something similar . (a temp solution I'm using is to store them in a Long Area Text field, but I think there's a more efficient solution).

3 Answers 3

8

I do it like this, if I want to see records in the debug log. Or query for them directly in execute anonymous and debug them from there.

string s = '';
for (record__c r : listOfThings) s += '\n' + r;
system.debug(s);
11

You could use JSON serialization to format all the records in the collection.

E.g.

List<Account> accs = new List<Account>();
for(integer i = 0; i < 50; i++) {
    accs.add(new Account(Name='Account-'+i));
}
System.debug(JSON.serializePretty(accs));
1
  • Definitely the best answer - no need for a loop to print the List
    – cyberspy
    Sep 3, 2021 at 9:18
1

you don't need to change code for this. There is a Chrome plugin which shows debug log nicely formatted. This is the link to that plugin: https://chrome.google.com/webstore/detail/apex-debugger/mpckkbblhbfngaininanfjpdfjhbncjo?hl=en

1
  • This won't change the fact that, for Lists that are printed, only 10 values are sent to the debug log. You can see this if you view the raw log - no amount of 'pretty printing' is going to 'expand' the 3 little dots at the end of a line into actual values. Still, looks an interesting plugin so I'm gonna give it a try anyway - just not for the reason you suggest ;)
    – cyberspy
    Sep 3, 2021 at 9:14

You must log in to answer this question.