Intro to the Salesforce Command Line Interface for Admins

awesomeadmin 3,524 views 50 slides Sep 04, 2019
Slide 1
Slide 1 of 50
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50

About This Presentation

A few years ago, Salesforce introduced a new tool to make changes to your org: the Salesforce Command Line Interface (CLI). While it was introduced as one of the Salesforce DX (Developer Experience) tools, there are plenty of features to supercharge your work as an Admin. Join Salesforce experts Mar...


Slide Content

Introduction to the Salesforce
Command Line Interface (CLI)
for Admins

Marc Baizman
Director, Trailhead
Content Engineering
Salesforce
@kierenjameson
Co-Founder RAD Women
WomenCodeHeroes.com
Kieren Jameson
Sr. Admin Evangelist
Salesforce
@mbaizman
Today’s Speakers
Developer Evangelist
Salesforce
@pchittum
Peter Chittum

Forward-Looking Statement
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if
any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-
looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of
product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regardingstrategies or plans of
management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments
and customer contracts or use of our services.
The risks and uncertainties referred to above include –but are not limited to –risks associated with developing and deliveringnew functionality for our
service, new products and services, our new business model, our past operating losses, possible fluctuations in our operatingresults and rate of growth,
interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any
possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and
motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-
salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factorsthat could affect the financial
results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for
the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor
Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not
be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently
available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Statement under the Private Securities Litigation Reform Act of 1995

Connect with Us!
@SalesforceAdmns
#AwesomeAdmin
admin.salesforce.com
SalesforceAdmins
SalesforceAdmins
SalesforceAdmins

Watch the Recording
The video will be posted to
YouTube & the webinar recap
page: bit.ly/CLIforadmins
This webinar is being recorded!

Join the Admin Webinar Group for Q&A!
bit.ly/AdminWebinarGroup
Don’t wait until the end to ask your
question!
We have team members on hand to answer
questions in the webinar group.
Stick around for live Q&A at the end!
Speakers will tackle more questions at the end,
time-allowing

●Introduction
●Learn the Command Line (& Demo!)
●Use the Command Line with Salesforce (& Demo!)
●Resources
●Q&A
Today’s Agenda

Marc: Admin, learned to use CLI* to do annoying data
things
Kieren: Admin, engineering manager, want to know a
little of all-the-things, want to use CLI for GitHub
Peter: Developer, started with CLI in the 80s/90s,
fell in love with GUIs*, rediscovered CLI 5 years ago,
“competent” with CLIs
*CLI = Command Line Interface
*GUI = Graphical User Interface
We’re just like you...

Introduction to the Command Line
Any Admin can benefit from learning the command
line!

“A command-line interface (CLI) is a means of
interacting with a computer program where
the user...issues commands to the program in
the form of successive lines of text (command
lines).”
ref. Wikipedia: Command-line Interface
What is the Command-Line Interface?

Any time you issue a text-based command to an app, this is a form of
Command-Line Interface (CLI):
●Finder (on Mac OS) or Cortana (on Windows 10)
●Browser Address Bar
●Slack, Quip (slash commands like /giphyor /invite)
●Google Web Search(“site:” or “exact text”)
●Gmail Search(“label:friends” or “has:attachment”)
You Are (Probably) Already Using Command Lines
Even @mentioning someone on
Facebook/LinkedIn/Twitter/Chatter counts!

Google and Gmail Examples

Power
Speed
Batch processing
(repetitive tasks)
Why Use the Command-Line Interface (and not GUI)?
!
"
#$%&

There Is a Learning Curve, but We Think It’s Worth It

Learn the Command Line

How Does the Command Line Work?
Input Output
Typed Command

date --utc
Anatomy of a Command
commandparameter
(or option)
date -u
most parameter
have abbreviations
output: Thu 22 Aug 2019 09:06:30 UTC

Important Commands “Bash Family” (Mac, Linux, Unix)
What do you want to do?CommandStands forExample
Move around the file systemcdChange directorycd folder_name/
Show where you currently arepwdPrint working directorypwd
Display what’s in a directorylsListls -al
Make an empty filetouchUpdate timestamptouch empty.txt
Create a foldermkdirMake directorymkdr new_folder
Copy a file or foldercpCopycp myfile1 new_folder/myfile1
Move or rename file or foldermvMovemv myfile1 new_folder/myfile1
Delete this file or folderrmRemoverm -r new_folder
Delete an emptyfolderrmdirRemove directoryrm new_folder
Look for a file with text in it that
matches this pattern
grepGlobal regular
expression print
grep ‘find’ here.txt
Find and replace textsedStream editorsed r/this/that/
Display the contents of filescatConcatenatecat myfile.txt myotherfile.txt
Output text echo echo text1

Important Commands PowerShell (Windows 7+)
What do you want to do?Command (alias)Example
Move around the file systemSet-Location (cd)cd folder_name/
Display where you currently areGet-Location (pwd)pwd
Display what’s in this directoryGet-ChildItem (dir)dir
Make an empty shell of a fileNew-Item New-Item empty.txt
Create a folderNew-Item (mkdir)New-Item new_folder -Type Directory
Copy a file or folderCopy-Item (cp)cp new_folder new_folder_2
Move a file or folderMove-Item (mv)mv file1 new_folder/file1
Delete this file or folderRemove-Item (del)del folder_or_name
Look for a file with text in it that
matches this pattern
Select-String (sls)grep "find"here.txt
Find and replace using pattern
matching
Display the contents of a fileGet-ContentGet-Content myfile.txt
Output text somewhereWrite-OutputWrite-Output "text1"

Semicolon: Do the First Command; Then Do Another One
;
cd;pwd

Pipe: Send Output From the First Command to the Second
|
cat names.txt| sort

(Careful…this wipes the previous contents of the file)
Redirect: Write Output From First Command to a File
>
echo "text1" > myFile.txt

Append: Write Output From First Command to the
End of a File
>>
echo "text2" >> myFile.txt

Only Do the Second Command If No Error on the First One
&&
cat file.txt && rm file.txt

Important Operators
What do you want to do?OperatorAkaExample
Pass output to the next command|Pipecat names.txt|sort
Write output to a new file>Redirectecho "text1" > myFile.txt
Append output on the end of a file>>Appendecho "text2" >> myFile.txt
Strings commands together; cd;pwd
Only do the 2nd thing if no error on first&&cat file.txt&& rmfile.txt
Use this key......to do this
TabAuto-complete what you’ve started typing
Ctrl-c (CTRL even on Mac)Stop a process that’s not ending on its own
⬆and ⬇ move through the history of your typed commands
Important Features (of most command line interfaces)

Command Line “Recipes”
Recipe What does it do?
ls -la > files.txtShows all files in a directory
cd;pwd gets you to your home directory, shows you
grep ‘old’ file.csv| sed‘s/old/new/’ >
cleaned.csv
Looks for lines with “old” in file.csv, replaces it
with “new”, and creates a new file cleaned.csv
grep -E "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-
]+\.[A-Za-z]{2,6}\b"
Looks for wonky emails
(found on the internet!)
head -n 1 file1 | cat -file2 > file3Gets the first line of file1, concatenates it to
the top of file2, creates a new file3

Live Demo: Data Management with Command Line
We get incoming lead data from a regularly occurring happy hour event
where people enter their info on a tablet and it is low quality.
Problems include:
•Lead ratings are incorrect
•Invalid emails (missing domains, periods, weird punctuation)
You don’t want to import that bad data!
Solution: Clean it before it gets into Salesforce with...the command line!
Scenario: Happy Hour Leads

Live Demo!
Data Management with Command Line
(Free yourself from Excel)

Use the Command Line With Salesforce
A new way to meet your org

Salesforce Command Line Interface
●Create and manage sandboxes or scratch orgs
●List your orgs and assign them aliases (aka nicknames)
●Get data in and out of Salesforce
●Get org limits
Salesforce CLI Command Reference
What can you do?

Install the Salesforce CLI
1)Install the Salesforce Command Line Interface
2)Test the Salesforce Command Line Interface
Open your command line (using Terminalon Mac, PowerShellon
Windows) and type:
sfdxupdate
Operating System Installer Link
macOShttps://sfdc.co/sfdx_cli_osx
Windows 32-bithttps://sfdc.co/sfdx_cli_win
Windows 64-bit https://sfdc.co/sfdx_cli_win64

Sample Development Workflows
Production Org
(Dev Hub)
Sandbox Orgs
(clones of production)
Metadata
settings
(and data)
Scratch Orgs
Version Control
Metadata
settings & data
Metadata settings
Version Control System
(a.k.a. your source)

Good for team development esp.
with a version control system (VCS)
Short lived (max of 30 days) without
your customization, but you can
load them using a definition file.
You might spin up a new scratch org
when you want to:
●Test a feature that you don’t
have available in production
(Bots, CPQ, etc.)
●Work with a team of admins
and developers
What Is a Scratch Org and Why Should I Use One?
References: Set up SFDX
Production
Org
(Dev Hub)
Scratch
Orgs
Metadata
settings
(definition
file)
and data
Metadata settings
Version Control
System
(a.k.a. your source)

Authorizing a Dev Hub
You can use a limit on
the number of Scratch
Orgs
You track these limits
through a Dev Hub org
(for most customers in
their production org)
Production
Org
(Dev Hub)
Scratch
Orgs
Metadata
settings
and data
Metadata settings
Version Control System
(a.k.a. your source)

sfdxforce:org:create-f config/project-scratch-def.json
--durationdays30
Spin Up a Scratch Org Using the CLI
SFDX commanddefinition file
location
how many days this
org will live
References: Create Scratch Orgs, Select the Salesforce Release for a Scratch Org

How do I get my customizations into a “blank”
scratch org? Through a scratch org definition file
(abc_definition_file.json)
This has all the configuration and data for your
scratch org
This allows you to have different “shapes” of
scratch orgs to test out different things
Scratch orgs come with the same set of data as the
edition they were based on
or “Where did my customizations go?”
Scratch Org Definitions
References: Scratch Org Definition File, Scratch Org Definition Configuration Values, Ways to Add Data
to Your Scratch Org, Importing and Exporting Data from a Scratch Org
Three scratch orgs with three
different configurations

Example Definition File

SOQL pulls data out of Salesforce
SELECT-What fields do you want?
FROM-Where are these fields stored?
WHERE-What filters do you want to use?
Salesforce Object Query Language (SOQL)
SELECT Id, NameFROM accountWHERE id = '0012E0000012yU6QAI'
fields you wantlocation of fieldsyour filters
SOQL
Salesforce
Account object
Data matching
your query

Use SOQL In Salesforce CLI
sfdxforce:data:soql:query
-r csv -q "SELECT Id, Name FROM
Account WHERE ShippingStateIN
('CA', 'NY')" > accounts.csv
SFDX commandSOQL query
(optional) file to save results
in
SOQL
Salesforce
Account objectData matching
your query
accounts.csv

Useful Salesforce CLI Commands
Reference: Salesforce CLI Command Reference
CommandWhat does it do?
sfdxforce:org:login-u usernamelogin to an org
sfdxforce:org:listall the orgs I’ve logged into
sfdxforce:org:createcreates an org
sfdxforce:org:aliasmake an org alias
sfdxforce:data:soql:queryget some data
sfdxforce:data:record:updateupdate a single record
sfdxforce:limits:api:displayget my current org limits usage

Useful Salesforce CLI Parameters
ParameterWhat does it do?
-hget help on the command
-s define the SObjectto use (“Contacts”,
“Opportunities”)
-udefine the user you’re signing in as
-q define the query you’re going to run
-f reference a file path
-idefine the external ID
--jsonset the output format to be JSON

Create a list of all private reports and
dashboards that haven’t been run for a
year
sfdxforce:data:soql:query
-r csv -q "SELECT Id FROM Report USING
SCOPE allPrivateWHERE LastRunDate<
LAST_N_DAYS:365” > oldreports.csv
Create an alias for an existing sandbox
org
sfdxforce:alias:set
[email protected]
SFDX Command Line Recipes
Clone a sandbox with a definition file
sfdxforce:org:clone-t sandbox -f
config/dev-sandbox-def.json-u prodOrg
-a AliasForNewSandox-s -w 20
Clone a sandbox without a definition file
sfdxforce:org:clone
SourceSandboxName=SandboxToClone
SandboxName=NewSandbox-a
AliasForNewSandbox-t sandbox -s -u
devhub-w 20
Upsertdata from a CSV file
sfdxforce:data:bulk:upsert-s
MyObject__c -f ./path/to/file.csv-i
ExternalID__c

Live Demo: SFDX in Action
View Salesforce CLI commands
Authorizeanexistingorg(asaDevHub)
Show org limits (make sure we’re not maxed out)
Create a new sandbox org
Retrieve a list of private reports
Run a SOQL query
Export a list of records, redirect to a file to show the things we changed
Launch an org

Live Demo!
SFDX in Action

Summary & Resources

Summary
●CLI help you do things quickly. They can feel
intimidating, but you’re likely already using them.
●You can use them to interact with files and
settings on your computer. With the Salesforce
CLI, you can access and interact with data and
metadata within your Salesforce orgs.
●They have two basic parts: commands and
optional parameters.
●You can chain them together in a variety of ways
similar to how you can have nested functions
within formulas.
●People generally have a few key commands that
they use often, like favorite recipes.
●You can use the Salesforce
CLI to: spin up new scratch
orgs and sandboxes, import
and export data, and view
your limits.
●Scratch orgs are temporary
Salesforce orgs; great for
team development and are
used with version control
systems like GitHub or
GitLab.

Trailhead Resources
If you’re doing team developmentwith
multiple admins or a mixture of Admins
and Developers...
If you want to dip your toe in the water...
Quick Start: Salesforce DX
Look out for more
content at DF19
App Development
with Salesforce DX
Git & GitHub Basics

Resources to Get Started With CLI
General CLI Resources
●Command Line for Beginners
●21 Command Line Hacks(for PCs)
Salesforce CLI Specific Resources / Help
Documentation
●Salesforce CLI Command Reference
●Create, Clone, or Delete a Sandbox
●Create Scratch Orgs
●Select the Salesforce Release for a Scratch Org
●Scratch Org Definition Files
●Scratch Org Definition Configuration Values,
●Ways to Add Data to Your Scratch Org
●Importing and Exporting Data from a Scratch Org
●JSON file formatwith key-value pairs

Q&A
bit.ly/AdminWebinarGroup
Slides
bit.ly/CLIforadmins
Wrapping Up
Survey
Please complete
GoToWebinarsurvey