Monday, February 11, 2019

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
        }   
    }


No comments:

Post a Comment