javascriptsalesforceconsole.logaura-framework

how do I post debug messages in Salesforce from JS?


I was told by Trailhead to use console.log. I am pretty sure my log statements are being hit based on the behaviour of the UI, but I never manage to create a log file at all, much less any entries. (I am running in developer console).Attached is a code snippet that illustrates some of the calls I'm makingenter image description here


Solution

  • Client-side js console and server-side apex debug logs are 2 different things.

    You're supposed to open JS console (try F12 or ctrl+shift+J) and view the log statements in there. If there's nothing - your code is probably transpiled by SF to production rather than debug mode and they are cut out of the source code. SF massages your code a bit for example to produce something that works in Internet Explorer. Go to setup -> debug mode and add your user there, then refresh the page. Console.log(), debugger; statements etc should work better now. I'd expect this (and the "setup -> session settings ->disable persistent cache" trick to be explained in that trailhead?

    There was interesting idea to use platform events for logging. They can be replayed for up to 72h, have some limitations but potentially you could have all logs funneling into 1 place. Especially useful when you know issue is client side but debugging is hard (occurs only on certain mobile device and you don't have time to fiddle with Android Debug Bridge or whatever). Check https://youtube.com/watch?v=vUwO89sdGgI out or (different implementation) https://github.com/afawcett/eventlogging It's bit "pro" though, just to solve your immediate problem the js console should be enough