Tips & Tricks: SFDX Commands for VS Code
Alekhya Mandadi
Founder & Director | Salesforce Marketing Champion '20 | Toronto Women in Tech Salesforce User Group Co-Lead
The future of change sets remains uncertain and DevOps is a hot skill to learn to end your relationship with change sets. But its quite a learning curve and it took me 6 months to really embrace the change. In the last couple of months, I created 90+ pull requests. I feel like I have a super power which I didn't possess before. So, if you have any opportunity to learn, go all in on it.
If you are someone like me who doesn't remember CLI commands, you are going to want to save the following SFDX commands in a Google sheet or somewhere handy because it's not efficient to search Google every single time you want to run a command.
Display Scratch Org Info
To display scratch org details including scratch org url, username and expiration date:
Command: sfdx org:display
List Scratch Orgs
Lists all the orgs, categorizes by scratch or non-scratch orgs. Lists connection status, alias used, expiration dates, org IDs etc.
Command: sfdx org:list
Generate a Scratch Org Password
Generate a scratch org password so that you can change in UI or save your favorite password application
?Command: sfdx force:user:password:generate --target-org <insert username here>
Install Packages in your Scratch Org
Managed or unmanaged packages can be installed easily as long as you know the package ID. You can get the Package ID for lets say an AppExchange app by going to the listing and clicking on the links as if you were installing it. In the URL, you will see the package ID which starts with 04t.
Command: sfdx force:beta:install -p "INSERT Package ID here" -w 30 -r
领英推荐
Install Latest Version of SFDX
Updates your SFDX version to get the latest goodies!
Command: sfdx update
Push Only Specific Folders from Source to Scratch Org
Typically for LWCs you develop in your VS Code and push it to your target org. So, to push those changes up to your scratch org, you can deploy using the following command. Basically all you are doing is pushing your file which is in the folder on your local machine to a file in the cloud.
Command: sfdx force:source:deploy -p force-apps/deploy/main/default/lwc/testLWCComponent
I've used this method for permission sets, fields etc. Makes it much faster than doing in the UI especially because VS Code has find and replace, you can quickly make changes and deploy to your scratch org.
Remove Core Hooks Path
Sometimes I get this error when creating a pull request (PR) about hooks on the git. I am not entirely certain what the error is but this helps me get rid of that error and move forward with creating my (PR).
Command: git config --unset core.hooksPath
Connect to a Scratch Org Created by Someone Else or Another Machine
This happened to me recently where I was using my scratch org in a remote desktop and then I had to switch to my local machine. So, I needed to make sure my local machine's VS Code is connected to the scratch org so that I don't lose my work:
Command: sfdx force:auth:web:login -a <desired alias> --instanceurl <instance url>
And then the usual stuff!
Then of course, you have all the good old stuff you can do with Control + Shift + P like Pull Source from Scratch Org and Push Source to Scratch Org. Won't go over those as those are pretty well documented. I like these few that I collected over the last few months and go back to these every now and then for the specific scenarios I mentioned. I hope you find it useful.
I'm the expert that leads teams through systems implementations from defining business requirements, and user stories to managing UAT and training SMEs to master a new/revised system for success.
2 年You are totally amazing!