Monday, February 11, 2019

What happened to my Salesforce System.Debug statements?


On our project we have complex report generation which creates a debug log file at the 5MB limit when the Apex Debug Log Level is set to finest.  According to Salesforce:

“Each debug log must be 5 MB or smaller. Debug logs that are larger than 5 MB are reduced in size by removing older log lines, such as log lines for earlier System.debug statements. The log lines can be removed from any location, not just the start of the debug log.“


If you just want to see the debug statements, simply log at the error level and then set everything else to none.

    System.debug(LoggingLevel.ERROR, ‘some logging message’);

Debug Levels
  • Database : None
  • Workflow : None
  • Validation : None
  • Callouts : None
  • Apex Code : Error
  • Apex Profiling : None
  • Visualforce : None
  • System:  None
  • Wave: None
  • Nba: None

If you want to debug in Visual Studio at the Apex finest level, break your code up into small testable pieces so that you can pinpoint errors and the log files can be under the 5MB limit.  The Single Responsibility should be your best friend when working in Salesforce.

Augmenting Salesforce CLI Commands for VS Code


I have been working with the Salesforce Extension Pack for VS Code and I have been mostly pleased with the capabilities.  On my current project, I find myself constantly switching between orgs.  I was tired of typing in the command to list out the current org and the command to switch the current org.  
There is a great hotkey VS Code extension called terminal-command-keys that allows you to create a hotkey that executes a terminal command.  The Salesforce CLI with hotkeys; what could be better!
Here are the steps to use
  1. Install the VS Code extension terminal-command-keys
  2. Edit your keybindings.json by pressing Ctrl-Shift-P on the PC or Command-Shift-P on the Mac.  Edit the file on the right



Add a command to list all your orgs by pressing Ctrl-Shift-l
    {
    "key" : "ctrl+shift+l",
    "command": "terminalCommandKeys.run",
    "args" :
        {
            "cmd": "sfdx force:org:list",
            "saveAllFiles": false
        }
    },

Add a command to upload the current file by pressing Ctrl-Shift-u
    {
        "key": "ctrl+shift+u",
        "command": "terminalCommandKeys.run",
        "args": {
            "cmd": "sfdx force:source:deploy --sourcepath  ${file} --loglevel fatal",
            "newTerminal": false,
            "saveAllFiles": true,
            "showTerminal": true
        }
    },

Add a command to switch to your development org.  In my case, the alias is BossSand. Replace with the alias for your org.
    {
        "key" : "ctrl+shift+d",
        "command": "terminalCommandKeys.run",
        "args" :
        {
            "cmd": "sfdx force:config:set defaultusername=BossSand",
            "saveAllFiles": false
        }
    },

Add a command to switch to your test org.  In my case the alias is BossStage. Replace with the alias for your org.
    {
        "key" : "ctrl+shift+v",
        "command": "terminalCommandKeys.run",
        "args" :
        {
            "cmd": "sfdx force:config:set defaultusername=BossStage",
            "saveAllFiles": false
        }   
    }