Newer Version Available

This content describes an older version of this product. View Latest

How sf and sfdx Work Together

The sf and sfdx commands play nicely together.

Environments

Currently, the only environments you can interact with are Salesforce orgs (scratch orgs, Dev Hubs, production orgs, sandboxes, and so on) and compute environments (where you deploy Salesforce Functions). Org authorizations are interoperable between sf and sfdx.

Specifically, when you create a scratch org, authorize an org, or log out of an org with sfdx, the sf commands respect these actions. The reverse is also true: if you log in or out of an environment in sf, the sfdx commands respect it.

For example, let's say you create a scratch org with sfdx force:org:create. When you run sf env list in the same project, the new scratch org is displayed.

Similarly, if you log into an org with sf login org, then run sfdx force:org:list, the org you logged into is displayed.

Aliases

Aliases are interoperable between sf and sfdx.

For example, if you run sfdx force:org:create --setalias MyScratchOrg, you can use this alias in sf, such as sf env open --target-env MyScratchOrg.

Similarly, if you run sf login org --alias MyDevHub, you can use this alias in sfdx, such as sfdx force:org:open --targetusername MyDevHub.

Configuration Variables

Configuration variables are interoperable between sf and sfdx. But their names are different, as shown in this table, which lists all available configuration variables in both sf and sfdx. It also lists the equivalent sf environment variable; see Environment Variables for the full list.

sf Configuration Variable Equivalent sfdx Configuration Value sf Environment Variable
disable-telemetry disableTelemetry SF_DISABLE_TELEMETRY
org-api-version apiVersion SF_ORG_API_VERSION
org-custom-metadata-templates customOrgMetadataTemplates SF_ORG_CUSTOM_METADATA_TEMPLATES
org-instance-url instanceUrl SF_ORG_INSTANCE_URL
org-max-query-limit maxQueryLimit SF_ORG_MAX_QUERY_LIMIT
org-metadata-rest-deploy restDeploy SF_ORG_METADATA_REST_DEPLOY
target-dev-hub defaultdevhubusername SF_TARGET_DEV_HUB
target-org defaultusername SF_TARGET_ORG

Let's run through a few use cases to see how the interoperability works, using target-org and defaultusername as examples. The same behavior applies to the rest of the configuration variables. Here's the general rule: if you set target-org to a value, then defaultusername is also automatically set to the same value. And vice versa.

Action: Use this sfdx command to create a scratch org:
1sfdx force:org:create --setdefaultusername -f config/project-scratch-def.json --setalias my-scratch-org

Then run sfdx config:list and sf config list.

Result: Both defaultusername and target-org are set to my-scratch-org.

Action: Use this sf command to set the target-org configuration variable to an org with alias uat-testing-org:
1sf config set target-org=uat-testing-org

Then run sfdx config:list and sf config list.

Result: Both defaultusername and target-org are set to uat-testing-org.

Action: Use this sfdx command to set the defaultusername configuration variable to an org with alias production-org:
1sfdx config:set defaultusername=production-org

Then run sfdx config:list and sf config list.

Result: Both defaultusername and target-org are set to production-org.

Action: Use this sf command to set defaultusername:
1sf config set defaultusername=other-org

Result: Error, because you can't use sf commands to directly set defaultusername.

Action: Use this sfdx command to set target-org:
1sfdx config:set target-org=other-org

Result: Error, because you can't use sfdx commands to directly set target-org.

Install an sfdx Plug-In into sf

Because both sf and sfdx are built on the open-source CLI framework (oclif), you can successfully install and use plug-ins originally built for sfdx in sf. However, you see these discrepancies in the --help and command output:

  • The --help content likely assumes you’re running the commands in sfdx. So the command examples show using sfdx instead of sf, use colon separators instead of spaces, and so on.
  • Similarly, the command output reflects the sfdx style. For example, if you install the @oclif/plugin-commands plug-in and then run sf commands, all the commands are correctly listed. However, the commands are displayed with colon separators and their description is the first line of the long command description rather than the short summary.