Spread the love

For the #MadeInItaly series where I want to showcase amazing artisanal Italian products from our incredible Italian Ohana, today’s guest post is delivered by Paolo Carrara, software developer, tech enthusiast, scrum master. After a Master’s degree in Software Engineering, he approached Salesforce ecosystem during his early career in a consulting firm and since then he’s been learning, coding, and thinking about new ways to improve his and his team’s work. A huge fan of the Agile movement and an active collaborator of the Italian agile community. You can visit his page (watch out for a hidden easter egg) here.


Many time things don’t go as we planned; we certainly don’t wish so but we must be prepared in such occasions, and when problems happen, there’s one just key factor: time.

That’s why I developed a tool that could help me get to the core problem quicker than whatever I was previously doing.

And that tool is SFDX Lens, a VS Code Extension available for free on the marketplace.

The typical scenario is this: you are happily developing the next new business logic in Salesforce when suddenly you get 3 different issues from 3 different users in your ticketing system, all marked with high priority. Ugh.
Now once you’ve read the ticket to understand what’s the problem you have to switch from your code to your QA environment, go to Setup > Debug Logs > New > compile all the required fields .. oh no! you have just created the 10th trace flag for the same user that was in debug last week.
Anyway, now you’re ready and can (if possible) replicate the issue, switch back to VS Code and inspect the log

And you have to do it 2 other times.

Or, you can leverage SFDX Lens’s Command SFDX Lens: Debug user from Org. With this command, the extension lets you pick just 3 options:

  1. An Org from the ones configured in your VS Code
  2. An active user to debug
  3. An amount of time from 15, 30 and 60 minutes

That’s it.

The extension will take care of setting a trace flag for that user with the maximum amount of precision allowed for the trace flag (which is more or less FINEST to everything), a process that usually take 1-2 seconds, and then you’re ready to replicate the issue and get the log in VS Code.

>Can you ask your user to replicate the issue himself?

Even better, “let me just activate the extension”, and 2 seconds after there you go, “go ahead”.

>Are you already connected to the QA environment?

Even better, you can skip point 1. With the command SFDX Lens: Debug user which creates a trace flag in the environment you’re connected to.

>Don’t want to search for the command in VSCode?

There’s a neat button for the command SFDX Lens: Debug user just in the activity bar below your code.

You don’t have to worry about trace flag pollution anymore, the extension ensures there will be just one trace flag per user (which is, the minimum required to set a trace flag)

Here’s a demo:

Right, now you have the log in VSCode and it’s a monolith of 7500 rows so.. what’s exactly happening here?

To address this question I often ask myself, I’ve developed a new command, right now in beta : SFDX Lens: Log Analysis (Beta) 

This command helps splitting the log into its components, each displayed visually and proportionally to its duration, so now you can focus on a single execution event at a time

This is particularly useful even for performance tuning, now you can see how many times a trigger fires per execution for example.

Here’s a demo:

Everything is made possible through the use of the @salesforce/core package available here: https://github.com/forcedotcom/sfdx-core

Now the circle is complete between getting the debug logs and analyzing them without leaving your IDE.