Developer webinar: Intro to command lines and the salesforce CLI
1. Intro to Command Line and the Salesforce
Command Line Interface (CLI)
11 September, 2019
Peter Chittum, Developer Evangelist
Kieren Jameson, Director Trailhead Content Engineering
2.
3.
4. 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 regarding strategies 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 delivering new functionality for our service, new
products and services, our new business model, our past operating losses, possible fluctuations in our operating results 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 factors that 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.
Forward-Looking Statement
Statement under the Private Securities Litigation Reform Act of 1995
5. Intro to Command Line and the Salesforce
Command Line Interface (CLI)
11 September, 2019
Peter Chittum, Developer Evangelist
Kieren Jameson, Director Trailhead Content Engineering
10. Peter: Developer, started with CLI in the 80s/90s,
embraced GUIs, rediscovered CLI 5 years ago,
“competent” with CLIs
Kieren: Admin who codes, engineering manager, want to
know a little about all-the-things, love dev puzzles, use CLI
for GitHub
We’re just like you...
12. “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?
14. Any time you issue a text-based command to an app, this is a form of command-line interface
● Finder (on Mac OS) or Cortana (on Windows 10)
● Browser Address Bar
● Slack, GitHub, Quip (slash commands like /giphy or /invite)
● Google Web Search (“site:” or “exact text”)
● Gmail Search (“label:friends” or “has:attachment”)
Even @mentioning someone in Facebook/LinkedIn/Twitter/Chatter counts!
Fun Fact: You’re (probably) already using a command line
23. Move around your file system
Unix-based
cd
cd ~
cd ..
cd child
cd child/grandchild
cd /
PowerShell
Set-Location [alias: cd]
Set-Location ~
Set-Location ..
Set-Location child
Set-Location childgrandchild
Set-Location C:
24. Show the contents of a directory
Unix-based
ls
ls
ls -al
PowerShell
Get-ChildItem [alias: ls, dir]
Get-ChildItem
Get-ChildItem -Attributes Hidden
27. Find and replace text
Unix-based
sed
sed 's/this/that/' file.txt
sed 's/this/that/g' file.txt
sed 's/this/that/I' file.txt
PowerShell
Get-Content with -replace
gc file.txt | %{$_ -replace 'this',
'that'}
(gc file.txt).replace('this', 'that')
28. Important commands for the “bash family” (Mac, Linux, Unix)
What do you want to do? Command What is stands for Example
Move around the file system cd Change directory cd folder_name/
Show where you currently are pwd Print working directory pwd
Display what’s in a directory ls List ls -al
Make an empty file touch (updates time stamp) touch empty.txt
Create a folder mkdir Make directory mkdr new_folder
Copy a file or folder cp Copy cp myfile1 new_folder/myfile1
Move or rename file or folder mv Move mv myfile1 new_folder/myfile1
Delete this file or folder rm Remove rm -r new_folder
Delete an empty folder rmdir Remove directory rm new_folder
Look for a file with text in it that
matches this pattern
grep Global regular
expression print
grep 'find' here.txt
Find and replace text sed Stream editor sed r/this/that/
Display the contents of files cat Concatenate cat myfile.txt myotherfile.txt
Output text echo (output to stdout) echo text1
29. Important commands for PowerShell (Windows 7+)
What do you want to do? Command (alias) Example
Move around the file system Set-Location (cd) cd folder_name/
Display where you currently are Get-Location (pwd) pwd
Display what’s in this directory Get-ChildItem (dir) dir
Make an empty shell of a file New-Item New-Item empty.txt
Create a folder New-Item (mkdir) New-Item new_folder -Type Directory
Copy a file or folder Copy-Item (cp) cp new_folder new_folder_2
Move a file or folder Move-Item (mv) mv file1 new_folder/file1
Delete this file or folder Remove-Item (del) del folder_or_name
Find and replace text .replace (gc file.txt).replace('this',
'that')
Look for a file with text in it that
matches this pattern
Select-String (sls) sls "find" here.txt
Display the contents of a file Get-Content Get-Content myfile.txt
Output text somewhere Write-Output Write-Output "text1"
31. Pipe: Send output from the first command to the second
|
cat bigFile.txt | less
Note: Type “q” to exit out of this
32. (Careful…this wipes the previous contents of the file)
Redirect: Write output from first command to a file
>
echo "text1" > myFile.txt
References: Echo Commands in Linux with Examples
33. Append: Write output from first command to the end of a file
>>
echo "text2" >> myFile.txt
34. Important Operators
What do you want to do? Operator Aka Example
Pass output to the next command | Pipe cat names.txt|sort
Write output to a new file > Redirect echo "text1" > myFile.txt
Append output on the end of a file >> Append echo "text2" >> myFile.txt
Strings commands together ; cd;pwd
Use this key... ...to do this
Tab Auto-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)
35. Command Line “Recipes”
Recipe What does it do?
ls -la > files.txt
Shows 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 > file3 Gets the first line of file1, concatenates it to the top
of file2, creates a new file3
36. Demo Scenario: Basics of CLI
Let’s take these commands out for a spin.
On the way we’ll show you how to create a new and improved forward
looking statement.
42. For everyone
Modern Application Lifecycle Management
Plan
Code
BuildTest
Release
CLI for integration with 3rd
party editors
Development Environments:
Scratch Orgs & Dev Sandboxes
Lightning Dev Pro Sandboxes
Continuous Delivery/ build
automation
Continuous integration with
test automation
Test Environments
Partial & Full Sandboxes
for UAT, staging
Packaging
Source Control
Repository
IDEs, Text Editors,
Language Services
Org Development
BETA
44. Salesforce CLI
Connect your laptop to any org
Access common Salesforce APIs
Universal: same on Windows or Mac
Pluggable
Use community-built plugins
Write custom plugins
Not the “Salesforce DX” CLI
Check Out Shane McLaughlin's Directory of Awesome CLI Plugins
46. How a Salesforce CLI Command Works
Windows, Mac, and Linux support
Salesforce CLI
Action to take
(Plugin)
Parameters
sfdx force:data:record:get -s Contact -w Email=jane@some.com –u UserAlias
47. Useful Salesforce CLI parameter
Reference: Salesforce CLI Command Reference
Parameter What does it do?
-h get help for a command
-u define the user (and org) for executing the command
-s which SObject (with data) or set default user (with auth)
-a define an alias
-f reference a file path
-i define the external ID
--json set the output format to be JSON
48. What the Salesforce CLI Can Do
Apex (logs, execute, test)
Authorization (OAuth, login)
Data Management
Lightning (lint, test)
Packaging
Limits (API, Reports, etc)
Org (create, delete, open)
Schema (list, describe)
User (assign perm sets)
Salesforce CLI Command Reference
52. Summary
● Anyone can use a Command Line Interface
● Productivity comes with practice
● Salesforce CLI for Salesforce developer productivity
53. Trailhead Resources
If you’re doing team development with
multiple admins or a mixture of admins and
devs...
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
54. Resources for Learning CLI
General CLI Resources
● Command Line for Beginners
● PowerShell Utility Reference
● List of Command LIne Commands
Salesforce CLI Specific Resources
● Salesforce CLI Command Reference
● TrailheaDX Talk: If You Can Write a Salesforce
Formula, You Can Use the Command Line
● TrailheaDX Talk: Apply the Salesforce CLI to
Everyday Problems
● Batch Examples in everyday-cli git repo