How to print ALL the elements of a List<>?

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));

Tags:

List

Debug