Nice Little Trick To Debug Apex Method Result Set In Javascript - Lightning Framework

The usual route we take when it comes to Debugging Apex methods is using `console.log()` method.

When we work on creating Lighnting Components, for sure there will be a situation where we might be interested in debugging the code.

The usual route we take is using console.log() method. While this approach works like a charm, it’s not effective when it comes to debugging the result-set which is basically a huge list of either Salesforce SObject or Custom Object records.

Reason being — response rendered in JSON format.

Everything that console.log() does is it logs the JSON response in the console panel of the browser. In case of a result-set which has a huge JSON response understanding it or analysing it becomes confusing with console.log().

In such cases we prefer to dump the response on lightning component between <aura:iterate /> tag and try to get a hang of the result set.

Doesn't it make our lives lot more happier if the result-set is rendered in a tabular format like this ...

console-table

Now let me tell you the JavaScript way of dealing with it and it’s console.table(). All it does is — it takes the JSON response and renders the output in a nice tabular format in the console window.

This is how we can use it in the callback function.

carbon

I will be publishing a series of articles on such nice little tricks that we can use to speed up the development. Stay Tuned !!

You can find the web series here Salesforce Platform & Lightning Training with more than 150+ videos.

What's coming next?

Am working on Apex Triggers Series - please subscribe to get notified.