2. ABOUT ME
Salesforce Application Engineer @ Meta
Salesforce Author @ Pluralsight
www.apexsandbox.io
SF DEPLOYMENTS WITH VS CODE & CLI 2
3. AGENDA
Install VS Code, CLI, Extensions
Creating Projects and Connecting to Orgs
Retrieving Metadata
Deploying Metadata
Fun with Package.xml
SF DEPLOYMENTS WITH VS CODE & CLI 3
4. INSTALLATION
Install Visual Studio Code
https://code.visualstudio.com/download
Install Salesforce CLI
https://developer.salesforce.com/tools/salesforcecli
Once installed, open a terminal and run `sf –-version` to verify
Install Salesforce Extension Pack for VS Code
1. Open VS Code
2. Ctrl+Shift+X or click “Extensions” on the left pane
3. Search for “Salesforce Extension Pack” and click install
SF DEPLOYMENTS WITH VS CODE & CLI 4
5. UNDERSTANDING THE SALESFORCE CLI
COMMAND LINE
INTERFACE
Graphical User Interfaces are
point-and-click interfaces
Application Programming
Interfaces are for other
applications
Command Line Interfaces are
for accessing a system through
the command line
SALESFORCE
EXTENSIONS + CLI
The Salesforce Extensions for
VS Code run CLI commands in
the background for many
operations
CLI REFERENCE
Check the docs to see what
commands you can run
https://developer.salesforce.co
m/docs/atlas.en-
us.sfdx_cli_reference.meta/sfdx
_cli_reference/cli_reference_un
ified.htm
SF DEPLOYMENTS WITH VS CODE & CLI 5
6. CREATE AN
SFDX PROJECT
Most Salesforce CLI commands only work
within an SFDX Project
An SFDX Project is just a folder with a
specific structure and some specific files
7. CREATE AN SFDX PROJECT
STEP 1
In VS Code, press
Ctrl + Shift + P
(windows)
Cmd + Shift + P
(mac)
STEP 2
Type and select
`SFDX: Create
Project with
Manifest`
STEP 3
Enter a project
name
STEP 4
Select a folder in
which the project
should be created
STEP 5
Make sure the
project is open in
VS Code
SF DEPLOYMENTS WITH VS CODE & CLI 7
8. WHAT’S IN THE
PROJECT?
SF DEPLOYMENTS WITH VS CODE & CLI 8
force-app/main/default
This folder contains all metadata, e.g. objects, fields, classes, flows.
manifest/
This folder contains a file called package.xml, which we will learn a lot
about later
A lot of other stuff
We normally don’t need to touch any of the other stuff.
9. AUTHORIZE AN
ORG
To retrieve metadata, you first need to
connect the Salesforce CLI to an org
To deploy metadata, you need to connect
Salesforce CLI to yet another org
10. CONNECT TO AN ORG
STEP 1
Get your
username,
password and
login URL
You may need to
get the login URL
from Setup > My
Domain > Current
My Domain URL
STEP 2
Open the command
palette (Ctrl/Cmd +
Shift + P)
Type and select
`SFDX: Authorize
an Org`
STEP 3
Follow the prompts.
If using custom
login URL, enter
https://<My
Domain URL>
STEP 4
Wait for a browser
window to pop up,
and log into the
org.
Click “Allow” in the
browser window
when prompted
STEP 5
Your org is
connected!
Run `sf org list` to
see a list of all
authorized orgs
Check the bottom-
left of your window
to see it on the UI
SF DEPLOYMENTS WITH VS CODE & CLI 10
11. RETRIEVE
SOME
METADATA!
There are many ways to do this. Comes
down to three steps:
1. Specify what metadata needs to be
retrieved
2. Specify what org/connection to retrieve
the metadata from
3. Retrieve the metadata
12. RETRIEVE METADATA
SF DEPLOYMENTS WITH VS CODE & CLI 12
There are multiple ways to retrieve metadata
1. Run a CLI Command to retrieve specific metadata
2. Use the Org Browser to retrieve metadata
3. List the metadata in package.xml and retrieve it
4. Generate a package.xml with EVERYTHING and
retrieve it all!
Once retrieved, check the force-app folder for the
retrieved XML
13. SF DEPLOYMENTS WITH VS CODE & CLI 13
sf project generate manifest --from-org <org alias> -n allMetadata -d manifest
14. DEPLOY SOME
METADATA!
Once again, multiple ways to do this.
Comes down to three steps:
1. Specify what metadata needs to be
deployed
2. Specify what org/connection to deploy
the metadata to
3. Deploy the metadata
15. DEPLOY METADATA
SF DEPLOYMENTS WITH VS CODE & CLI 15
There are multiple ways to deploy metadata to an org
1. Run a CLI Command to deploy specific metadata
2. Right-click + deploy directly on a file or folder
3. List the metadata in package.xml and deploy it
16. RETRIEVE/DEPLOY DEMO
SF DEPLOYMENTS WITH VS CODE & CLI 16
Source org: empathetic-raccoon
Target org: playful-shark
Metadata:
• Robot__c custom object, custom fields, custom
tab, page layouts, sharing rules, trigger, and
custom fields
• Globomantics Basic Access permission set