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
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);
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));
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
-
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 ;)– cyberspySep 3, 2021 at 9:14