Jam-packed video on how to get an SFDX project up and running.We install Visual Studio Code, The Salesforce CLI along with the SFDX extension pack for VSCode. Like with any good development tool, there is more than one way to do things with Visual Studio Code. The two main ways you can interact with Salesforce CLI are through the integrated terminal or quick open window. To view the quick open window, press Command + P on Mac or Ctrl + P on Windows. You can view the help menu. Through this module we will use the quick open window in command.
10 Apr 2019
Table of Contents
- Software to install
- Download metadata files
- Edit and re-upload a configuration file
- Keep the files on your computer up-to-date over time
A colleague wanted to edit the XML behind Salesforce flows so she could quickly copy/paste entire flows, copy/paste variables within a flow, etc.
That part is easy, but I needed to walk her through setting up her computer to talk to Salesforce about an orgâs configuration âmetadata.â
Hereâre the instructions I sent her for Windows.
Developers, you can skim the deep dive into downloading, editing, and re-uploading a flowâs XML, since you probably already know exactly which files youâre trying to edit.
Administrators, the idea behind this post is that sometimes, itâs faster or easier to change the structure of your Salesforce org by downloading files representing that structure to your local computer, editing them, and re-uploading them to Salesforce.
Think of it like using the âData Loader,â but for your orgâs structure instead of its data.
I hear that copy-paste functionality will be back into the Salesforce Flow web editor as of summer â19, so this postâs example code will soon be a bit âdated.â
Nevertheless, the principle that you can make certain changes to your Salesforce org faster with code than you can with clicks may remain true with other pieces of your orgâs structure, so Iâll leave the tutorial up even after âcopy-pasteâ comes back in the web-based flow builder.
Did you get VSCode set up?
Yay! Iâm thrilled I could help.
If youâd like, Iâd love a Ko-Fi. (Chai for me!) đ„°
Need extra help on XML? Download Intro to XML, JSON, & YAML â the book
Painless and simple
The process of trying to edit my orgâs âmetadataâ with VSCode instead of Eclipse was not nearly as bad as I thought itâd be.
For well over a year, having heard bits and pieces of information about âDX,â I thought I was going to have to change everything about the way I pushed code to Salesforce, having been an Eclipse and âForce.com IDEâ user for years.
Luckily, thanks to Bonny Hinners, I learned that what Salesforce is pushing as its âSFDX org development modelâ means âchanging nothing about what you do except using VSCode instead of Eclipse.â
Super! No learning new things about SFDX packages! No worrying about managing Git repositories in new ways!
Salesforceâs official support for Eclipse is ending in six months, so itâs nice to have my moves down to make the switch to VSCode myself.
- (Edit: I finally migrated from Eclipse to VSCode.)
Thanks also to Nick Lindberg and Zayne Turner for evangelizing âVSCode for adminsâ so effectively and persistently (I got the hint!).
Computer admin rights
Note that if you donât have âadministratorâ rights on your computer, you may need them â or need someone from your IT department to help you install this software whenever the installers prompt for an âadmin password.â
Software to install
There are 4 pieces of software youâll need to have installed properly on your computer, per Salesforce documentation:
- The Java SE (âStandard Editionâ) JDK (âJava Developer Kitâ)
- Not to be confused with the more common Java SE JRE (âJava Runtime Environmentâ). This version is aimed at coders. Arenât you fancy now?
- The âSalesforce Command Line Interfaceâ or âSalesforce CLIâ
- Microsoft Visual Studio Code, or âVSCodeâ for short
- The âSalesforce Extensionsâ plugin package for Visual Studio Code
Note that a failed installation of any piece of this process could impact the next piece of the process.
Generally, if you have a choice of whether to let the installer add things to your âPATH environment variable,â you want to let them do so (itâs what makes codewords like java
and sfdx
be recognized by your computerâs command-line interface as valid commands that can take options and do cool things).
Javaâs JDK
Download an installer here from Oracle.
- You want the first box of options.
- Pick the appropriate installer for your computer (favoring 64-bit over 32-bit installers unless for some weird reason you need 32-bit).
Salesforceâs CLI
Download an installer here from Salesforce.
You should be able to test that it worked by opening a Windows command prompt (windows key on your keyboard, cmd
, enter) and typing sfdx âversion
and hitting enter.
- If you see text about the version as a response, yay. Type
exit
and hit enter and move on. - If Windows complains that
sfdx
is not a command, something went wrong with the JDK or the Salesforce CLI install. Youâre not going to get far when you try to do stuff in Visual Studio until you fix this.
Microsoftâs Visual Studio Code
Download an installer here from Microsoft.
This is an âIDE,â or âIntegrated Development Environment.â
In some ways, you can think of an IDE as a souped-up text editor, like Notepad++.
In this case, itâs the souped-up text editor of choice for dealing with the âmetadataâ text files that represent the way your Salesforce org is configured.
Like Chrome, there are a lot of Salesforce-related plugins available for it.
Also like Chrome, you really shouldnât install a plugin without a good reason to trust it.
Weâll start by just installing the ones that Salesforce publishes in our next steps.
For a brief overview of the user interface of VSCode, see the Trailhead module CumulusCI Setup: Review Base Requirements and Install Visual Studio Code.
Salesforceâs plugins for VSCode
These will ensure you have lots of friendly button-click options in VSCode, rather than having to memorize a million annoying commands that start with âsfdx
.â
Once youâve installed Visual Studio Code, visit this page of Visual Studioâs âmarketplaceâ in your web browser and click the big âInstallâ button at the top.
When your browser asks if you want to open the link with Visual Studio Code, let it.
Follow any prompts, but I think you should be good to go pretty fast.
Connect VSCode to a Salesforce org
This official documentation has screenshots of most of the steps below.
- Click on the little settings gear in the lower-left-hand corner of VSCode and click âCommand Paletteâ
- Start typing âSFDXâ and select âSFDX: Create Project With Manifestâ
- (Do not use plain-old âCreate Projectâ, which will probably be higher in the list of options)
- (Do not use plain-old âCreate Projectâ, which will probably be higher in the list of options)
- In the next pop-up, type a nice meaningful name like âHEDA â Sandbox - Stagingâ
- (My colleague was connecting to a sandbox called âStagingâ in a new org we were spinning up to start from scratch with HEDA).
- (My colleague was connecting to a sandbox called âStagingâ in a new org we were spinning up to start from scratch with HEDA).
- In the âSelect Folderâ Windows Explorer pop-up, create / find / navigate to a folder that seems like a good spot on your hard drive to keep copies of the code representing the contents of the org youâre about to download from.
- For example,
C:UsersYOUR_USERNAMEDocumentsCodebasesSalesforce Orgs
- For example,
- Click the âCreate Projectâ button
- Youâll see a âWelcomeâ thing with some folder navigation at left thatâs collapsible under the phrase âHEDA â Sandbox - Staging,â or whatever meaningful name you came up with.
- At this point, if you were to browse your hard drive, youâd notice a folder called
C:UsersYOUR_USERNAMEDocumentsCodebasesSalesforce OrgsHEDA --- Sandbox - Staging
or something similar.
- At this point, if you were to browse your hard drive, youâd notice a folder called
- Click on the little settings gear in the lower-left-hand corner of VSCode and click âCommand Paletteâ
- Start typing âauthâ and select âSFDX: Authorize an Orgâ
- Choose âSandboxâ if youâre connecting to a sandbox, etc.
- Choose a nice nickname like â
heda_sandbox_staging
â and hit enter - Your default web browser will bring you to a Salesforce login screen
- (Hopefully your default browser isnât set to auto-login w/ a saved password to a different org. If not, bail at the step asking to authorize âSalesforce CLIâ as you, turn off auto-login in your web browser, and try again from âSFDX: Authorize an Orgâ, I believe.)
- (Hopefully your default browser isnât set to auto-login w/ a saved password to a different org. If not, bail at the step asking to authorize âSalesforce CLIâ as you, turn off auto-login in your web browser, and try again from âSFDX: Authorize an Orgâ, I believe.)
- Log in to whatever Salesforce org youâre trying to connect to as yourself.
- Click the âAllowâ button letting âSalesforce CLIâ interact with Salesforce on your behalf
- You can now close the browser tab with that org open
Download metadata files
Now you need to download text files called âmetadataâ that represent the current state of your Salesforce org onto your computer so that itâs easy to edit their contents.
Salesforce only lets you edit a tiny bit of the âmetadataâ in your org directly through the web siteâs Developer Console (e.g. Apex triggers & classes).
All other âmetadataâ code has to be downloaded to your computer, edited there, and re-uploaded to Salesforce if you want to edit it directly.
Specify what files to request from Salesforce
- Back in VSCode, at left, under the navigation for the âprojectâ you just created and gave a nice name, expand the folder called âmanifestâ and double-click âpackage.xmlâ to open it in the text editor area of VSCode at right.
- Take a look at the file. Itâs full of text formatted in a pattern known as âXML.â
- Do you know how to read XML? Check out my tutorial if not!
- Itâs probably about 30 lines long and contains text between â
types
â tags with code meaning things like, âDownload all Apex classes to my hard drive from Salesforce,â âDownload all Custom Settings to my hard drive from Salesforce,â etc.
- Edit the file. Carefully. Read my XML tutorial if youâre nervous. What youâre trying to do is leave only â
<type>...</type>
â tagsets in the XML you need.- Delete â
<type>...</type>
â tagsets you donât care about (you donât need to see the details of Apex Triggers if you donât program them â itâs just going to make the download take longer). - Be sure not to accidentally delete the â
<version>...</version>
â tagset from your XML when deleting â<type>...</type>
â tagsets you donât need. - Add new â
<type>...</type>
â tagsets you do care about (learning exactly what to type is a bit of an art, but itâs usually pretty intuitive for most things if you start with an example), such as one for âFlow
â if thatâs what youâre trying to edit. - Official documentation is here
- A slightly overwhelming but official smorgasbord of example contents for a
package.xml
file is here
- Delete â
- Save your work. (âCtrl+Sâ in Windows or File->Save)
- You can close the editor window for
package.xml
now.
For example, if you just want flows, you can erase the entire contents of your package.xml
file and replace it with this code (perhaps upgrading the version number if youâre reading this much later than I wrote the post):
Thatâs all that goes in package.xml
! Not so bad, right?
(You can always re-edit it later if you want to fetch more or fewer files in subsequent requests to Salesforce.)
Ask Salesforce for the files
This is known as âretrievingâ code.
- Right-click on â
package.xml
â in the left-nav and click âSFDX: Retrieve Source in Manifest from Orgâ - When the little status box at lower right says youâre all done, close up âManifestâ at left and expand the folders âforce-app,â then âmain,â then âdefault,â then âflowsâ (presuming you meant to download flows).
- Do you see a lot of files? Yay!
- (If not, dummy check: you do have flows or Process Builders in your org, right?)
- (If not, dummy check: you do have flows or Process Builders in your org, right?)
Edit and re-upload a configuration file
Edit a file on your computer
- Open one up in the VSCode file editor by double-clicking it. Make it one thatâs still inactive and a first draft, and that you donât care much about if you break it.
- Make some sort of relatively foolproof edit.
- e.g. Copy & paste a â
<variable>...</variable>
â tagset and type a new value inside the â<name>...</name>
â tagset embedded within. - Do you know how to read and write XML? Check out my tutorial if not!
- e.g. Copy & paste a â
- Save your work (File->Save or Ctrl+S).
- Close the editor tab for the file you just edited.
Hereâre 4 screenshots of a flow I created with the web in Salesforce.
And hereâs the XML I downloaded through VSCode that represents it:
Wow! Thatâs a lot of code for very few boxes of Flow Designer, right? I suppose the difference between the visual and text representations of the same concept illustrate the reason that people often enjoy setting configurations with âclicks, not code.â
Nevertheless, the âcopy-pasteâ-ability of the text file canât be beat.
Iâm just going to copy-paste Variable_01
to be a 2nd variable, Variable_02
.
Upload the file back to Salesforce
This is known as âdeployingâ code.
- Back in your navigation menu at left, right-click on the file you just edited and click âSFDX: Deploy Source to Orgâ
- Unfortunately, you canât ctrl+click multiple files and deploy them all at once this way. Only one file will actually deploy, even though they all look selected on your screen.
- Deploying an entire folder works by right-clicking it and deploying. (Note: possibly dangerous if others have been editing those other files through the web â you could overwrite their work.)
- Similarly, you can right-click on
package.xml
to deploy all XML files mentioned therein from your computer to Salesforce. This has the same âyou might be deploying old codeâ caveat.
- Once VSCodeâs status pop-ups in the bottom right say youâre doneâŠ
- Open your Salesforce org, back out of your flow if you were editing it, re-open it, and see if the magic worked! Do you have a new variable in your resources?
Keep the files on your computer up-to-date over time
Now play with your flow in the web interface.
Save some changes.
To ensure you have a fresh copy on your computer before editing the XML representing your flow:
- Open VSCode
- Right-click on the file (or on the package.xml for everything) and do a âRetrieveâ instead of a âDeploy.â
Warning
Caution: Donât click the adjacent âdeployâ option!
Visual Studio Code Salesforce Cli Is Not Installed
Unfortunately, âRetrieveâ & âDeployâ are right next to each other.
- Q: Why wouldnât it be safe to deploy?
- A: As youâre aware if youâre trying to âretrieveâ code fresh from Salesforce, the copies of code on your computer are out-of-date.
- Accidentally clicking âDeployâ instead of âRetrieveâ could overwrite hard work youâve done through your web browser with no easy way to recover.
If I use VSCode re-open the XML file containing a representation of my flow, after re-downloading the latest version of it, I can see that itâs longer than it used to be..
Salesforce Vs Code Install
Change 1: Within the <assignmentItems>...</assignmentItems>
tagset representing the assignment called âSave Name,â an entirely new <assignmentItems>...</assignmentItems>
tagset has been added to the code setting the value of Variable_02
, just like I did with clicks.
Change 2: The <screens>...</screens>
tagset representing the screen called âGreeting Screenâ has been updated so that its âGreetingâ display-text field says âHello {!Variable_01} {!Variable_02}!
â instead of âHello {!Variable_01}!
â
Hooray â I successfully updated my computerâs copy of the XML code to keep it in sync with whatâs going on in my Salesforce org through web-based edits.
Your Turn
- If youâre an administrator, I hope you can make yourself more productive with a bit of âcode, not clicksâ
- If youâre a developer, now you can finally be less afraid of Salesforce ending support for Eclipse.
Thanks for making it all the way through!