The new Salesforce DX command-line tool

Pete Nicholls

Salesforce’s new Developer Experience (DX) made its debut today during the Salesforce for Developers Keynote. Over the course of 20 minutes, we got to see source control with git and GitHub, command-line deployment, scratch orgs, and continuous deployment with Heroku Pipelines. Powering all of this was a new command-line tool, sfdx.

We were curious to see what sfdx consisted of, so we took the liberty of transcribing the command-line tool’s help screen for your perusal.

$ sfdx force --help
  Additional commands, type "heroku help COMMAND” for more details:

  force:apex:exec               # execute anonymous apex code
  force:apex:limits             # display current org's apex governor limits
  force:apex:logs               # fetch debug logs
  force:apex:report             # retrieve and report test results for a given testrunid
  force:apex:test               # invoke apex tests
  force:api:limits              # display current org's limits
  force:bulk:delete             # bulk delete records from a csv file
  force:bulk:status             # view the status of a bulk data load job or batch
  force:bulk:upsert             # bulk upsert records from a csv file
  force:data:import             # imports data into workspace or target org using SObject Tree API
  force:ddl:delete              # delete a custom field or custom object
  force:ddl:upsert              # create or update an sobject and up to one field
  force:dml:create              # create a record
  force:dml:delete              # delete a record
  force:dml:get                 # view a record
  force:dml:update              # update a record
  force:login                   # log in to a salesforce org
  force:manifest:create         # creates manifest file
  force:mdapi:deploy            # deploys metadata to target org using metadata api
  force:mdapi:retrieve          # retrieves metadata from target org using metadata api
  force:org:authorize           # authorize a hub org
  force:org:create              # create a scratch org
  force:org:delete              # marks a scratch org for deletion
  force:org:open                # open an org in your browser
  force:packageversion:create   # Creates a new Package Version in the DE org
  force:packageversion:install  # Installs a Package Version in the target org
  force:permset:assign          # assign a permission set to the admin user of an org
  force:sobject:describe        # describe an object or list all objects of a type
  force:soql:query              # execute a soql query
  force:src:pull                # pull source from the workspace org
  force:src:push                # push source to an org
  force:test                    # invoke the test runner
  force:test:config             # help and validation on a test runner configuration file

Salesforce DX is not generally available yet, and still has some work to go, so everything listed here is liable to change. Some interesting observations can still be made, though.

It looks like a new version of the force command

When you compare sfdx to the force CLI, the commands listed look very similar, so it could be that we’ll see the update that way. It could also be that sfdx will replace the force command.

You can manage scratch orgs from the command-line

Booting up a scratch org for testing or review can be done from within sfdx. There is also a configuration file that can be used to customise the new org’s settings:

{
  "Company": "ACME Org",
  "Country": "US",
  "LastName": "Wegner",
  "SignupEmail": "wade.wegner@salesforce.com",
  "Edition": "Unlimited",
  "Features": "Multicurrency",
  "OrgPreferences":
    {
      "ChatterEnabled": false,
      "IsOrdersEnabled": true
    }
}

You can manage data from the command-line

The force:bulk command, for bulk-loading data, is going to be extremely useful for loading test data in scratch orgs. There are also two other subcommands, force:ddl and force:dml1, that will let you create, modify, and delete individual records.

You can interact with the source and the metadata separately

In the Keynote, they differentiated between “metadata” (configuration) and “source” (Apex code). sfdx has separate commands for handling source (force:src) from metadata (force:mdapi). Based on the presentation, it looks like this will work by syncing different directories within your repository – one for metadata, one for your Apex code.

You can run arbitrary code and queries

force:apex:exec seems to be a command for executing arbitrary Apex code. force:soql:query allows you to run arbitrary SOQL queries. Both could be useful for debugging or scripting.

You can kick off and view test runs

force:test and the force:apex:test subcommands give you a way to run your tests and view the results. This is great for CI.

sfdx seems to be based on the heroku CLI

At the beginning of the help screen, we can see this line:

Additional commands, type "heroku help COMMAND” for more details:

This suggests that sfdx is based on the one that ships with the Heroku Command Line Interface and is written in Node.js. As with the Heroku CLI, it will be possible to add plugins to this CLI.

1 DDL is short for Data Definition Language, and DML is short for Data Manipulation Language. Think of defining a schema versus editing the data within the schema.

→ Read more in our series on Salesforce DX: What does Salesforce DX mean for admins?

Salesforce Features Admins Dreamforce 2016 SFDX
Photo of Pete Nicholls
Pete Nicholls is a Karabiner developer based in New Zealand. He likes coffee and thinks you should follow Karabiner on Twitter.