Intro to the Salesforce Command-Line Interface Webinar Recap

By

One of our latest webinars, Introduction to the Salesforce Command-line Interface for Admins, is part of our Back to School webinar series where we cover technical skill development as well as the latest product updates. Director of Trailhead Content Engineering (Salesforce) Kieren Jameson, Developer Evangelist Peter Chittum (Salesforce), and Senior Admin Evangelist Marc Baizman (Salesforce) shared their expertise to help you get a basic understanding of how the Salesforce Command-line Interface works, how to learn it, and how it can benefit #AwesomeAdmins.

Take a look at the full recording:

Webinar Summary:

This special webinar combines the forces of the Developer and Admin skillsets to understand what the Salesforce Command-line Interface is and how to use it effectively in your day-to-day processes.

To start, we need to understand the definition of a Command-line Interface, or CLI for short. A 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)” (“Command-line interface”, n.d.). This means that instead of using the GUI, or graphical user interface, to point and click to interface with a computer, you’re only using lines of text. Fun facts on computer history: commands are typically short—for two reasons. 1) At the time these commands were being developed, memory on computers was quite low, and 2) commands were typed on a teletype machine which was a very difficult machine to type on, so the shorter, the better!

Oh, and in case you’re wondering when you’d ever come in contact with a command line, you probably already have, and quite regularly, too, without thinking about it! Marc sets the record straight, telling us, “Anytime you issue a text-based command to an app, this is a form of Command-line Interface.” Examples of this include Finder on Macs, Cortana on Windows, slash commands in Slack and Quip (/giphy or /invite), or a Gmail search (has:attachment). Even @mentioning someone on a social media platform counts!

Why Use the CLI instead of the GUI?

There are three main reasons to use the CLI instead of the GUI:
1) ??Power
2) ? Speed
3) ?‍?‍??‍?‍?‍? Great for batch processes (repetitive tasks)

In order to harness the power, speed, and efficiency of the Command-line, we first have to understand how it works. First, you have an input. Then, you have a typed command. Finally, some sort of output from that typed command.

To see this in action, Marc demonstrates with a very simple “date” command. Below you can see the input, actual typed command, and the output. It’s important to note that where you type the commands in depends on the operating system you use. With a Mac, you’ll want to use Terminal, and with Windows, PowerShell.

A Quick Start Guide To Commands

Another important resource for getting started is this “quick start” guide of commands in the “Bash Family” of commands. This list gives you an idea of what kinds of things you can accomplish by using the Command-line with Mac, Linux, and Unix.

And if you’re running Windows 7 or later, this quick start guide of commands should give you an idea of what is possible to accomplish. These commands are slightly longer and more descriptive, but there are shorter aliases that are also available, which mimic the bash commands, shown like (this).

Moving on, Marc dives into Operators. Operators are the things that happen in between commands. In this case, the semicolon “;” tells the computer to do the first thing, then do the next thing. Another Operator is the Pipe, or “|”. The Pipe sends the output from the first command to the second. Next, Redirect or “>” writes the output from your first command to a file. Careful! This Operator will wipe all previous contents of a file. Next, Append, or “>>” writes output from the first command to the end of a file. Finally, the “&&” operator performs somewhat like the semicolon BUT it will only execute the second command typed if there is no error on the first one. Think of it like the semicolon with some extra logic built in if you’re worried about whether or not the first command will work.

Check out this helpful Operator “dictionary” plus a few other important features:

Now that we’ve covered all of those individual components, what do you do with them? Marc explains, “The power of the Command-line is not just in one of the commands, it’s in combining all these commands into really cool recipes.” Take a look at a few examples:

Live Demo—Peter Chittum

And now, we dive into the first Live Demo portion of the webinar! Peter Chittum sets the scenario up where we understand that we get incoming lead data from a regularly occurring happy hour event, where people enter their info on a tablet but the info coming in is low-quality. Problems abound, like incorrect lead ratings and email addresses. You wouldn’t want to import bad data into Salesforce, so let’s learn how to use the Command-line to clean it before it goes in! Take a look and learn along with Peter as he demonstrates in real time.

The Salesforce CLI

The Salesforce CLI is a program you can install on your computer which enhances the functionality of the native command line to allow you to work with all of your Salesforce orgs. Not only can you create and manage sandboxes and scratch orgs but also get data in and out of your Salesforce orgs, as well as check things like governance limits, all with the CLI. So, how do you get this handy tool? Easy! Click one of the links below to install on your computer.

For Mac: www.sfdc.co/sfdx_cli_osx
For Windows 32-bit: www.sfdc.co/sfdx_cli_win
For Windows 64-bit: www.sfdc.co.sfdx_cli_win64

Check out Kieren’s walk-through:

Scratch Orgs & Scratch org definitions

What is a scratch org and why are they good for Admins? Kieren explains that scratch orgs are often used in a team environment and you can use them in conjunction with a version control system like GitLab, just like you would with sandboxes. But scratch orgs are dedicated, configurable, and short-lived (they max out at 30 days). They are “blank” versions of your org without any customization. They’re great to spin up when you want to test a feature that you don’t have available in production! Keep in mind that you can only have a certain number of scratch orgs at any given time, and to keep track of them, you need to have a Dev Hub enabled. For most people, their production org becomes their Dev Hub. For more on scratch orgs, take a look at how Kieren explains how to spin one up in the Salesforce Command-line:

Now, let’s talk about scratch org definition files. By default, scratch orgs come blank. So, we use the definition file to load up configurations—loading up different configurations for different orgs, if you want. As an Admin, if you’re testing out different page layouts, etc., you can test version A in one scratch org and version B in a different one because you can have a different definition file in each scratch org. Check out the example definition file and how it works:

Kieren shares that the coolest part about using the Salesforce CLI as an Admin is that it allows her to get data out of her org without actually going through the whole process of opening the org, creating a report, exporting data, etc. She explains that you do this by using SOQL, or Salesforce Object Query Language. SOQL has three main parts: select which fields you want, say where these fields are coming from, and where tells you which filters you want to use on the data.

The best part is that SOQL can be run directly from the Salesforce CLI!

Take a look at some of the other useful Salesforce CLI commands you can use, and the parameters that you may also find helpful. This section of the webinar also dives into SFDX Command Line recipes that you can easily start putting into practice. You can get started with those below:

SFDX Command Line Recipes

Create a list of all private reports and dashboards that haven’t been run for a year

 
sfdx force:data:soql:query -r csv -q "SELECT Id FROM Report USING SCOPE allPrivate WHERE LastRunDate < LAST_N_DAYS:365” > oldreports.csv

 

Create an alias for an existing sandbox org


sfdx force:alias:set MyDevSandbox=username@company.com.dev1

 

Clone a sandbox with a definition file


sfdx force:org:clone -t sandbox -f config/dev-sandbox-def.json -u prodOrg -a AliasForNewSandox -s -w 20

 

Clone a sandbox without a definition file


sfdx force:org:clone SourceSandboxName=SandboxToClone SandboxName=NewSandbox -a AliasForNewSandbox -t sandbox -s -u devhub -w 20

 

Upsert data from a CSV file


sfdx force:data:bulk:upsert -s MyObject__c -f ./path/to/file.csv -i ExternalID__c

Now, Peter shows another live demo, this time going through a set of Salesforce Command-line commands to help you understand how you can get started with them. Jump in and learn along with Peter:

Wow! That was a ton of awesome information. Your mind is probably turning and excited to put these Salesforce CLI tips and practices into action. So, where do you go from here? Check out these awesome resources from Kieren, Peter, and Marc:

To dip your toe in the water:
Trailhead—Quick Start: Salesforce DX
https://trailhead.salesforce.com/en/search?keywords=quick%20start%20salesforce%20dx
Team development:
Trailhead—Git and GitHub Basics
https://trailhead.salesforce.com/en/content/learn/modules/git-and-git-hub-basics
Trailhead—App Development with Salesforce DX
https://trailhead.salesforce.com/en/content/learn/modules/sfdx_app_dev

And for a larger list of resources to get started with CLI, check out slide 48 of this presentation:

Remove Security Risks from Your Org With a User Audit

The right level of user access is critical to security, and as an #AwesomeAdmin, you play a key role in strengthening the security of your org. With many of us working from home these days, hackers are increasing their efforts with phishing attacks targeting user credentials. The cybersecurity threat landscape is always evolving to include […]

READ MORE

Decoding Triggers for Admins: Webinar Recap

Our latest webinar, Decoding Triggers for Admins, is based on Kieren Jameson’s extremely popular Dreamforce ’18 breakout session and covers how #AwesomeAdmins can decode the basic structure of a trigger, learn how to get started with triggers, and understand the role they play in your org. Take a look at the recording:   Webinar summary: […]

READ MORE

Create Awesome Dashboards with the Lightning Report Builder

Our Salesforce Admins webinar, Master the New Lightning Report Builder with Marc Baizman and Liz Skaates is all about how #AwesomeAdmins can create “One Report to Rule Them All.” Marc and Liz dove deep into all the ways that Admins can use these features efficiently and effectively to work smarter, not harder, and present the […]

READ MORE