env Commands

Commands to manage your environments, such as orgs and compute environments.

env compute collaborator add

Add a Heroku user as a collaborator on this Functions account, allowing them to attach Heroku add-ons to compute environments.

Examples for env compute collaborator add

Add a Heroku user as a collaborator on this Functions account.

Usage

sf env compute collaborator add
[--json]
-h HEROKU-USER

Flags

--json
Optional

Format output as json.

Type: boolean
-h | --heroku-user HEROKU-USER
Required

Email address of the Heroku user you're adding as a collaborator.

Type: option

env create compute

Create a compute environment for use with Salesforce Functions.

Description for env create compute

Compute environments must be connected to a Salesforce org. By default the command uses your local environment's connected org. Use the '--connected-org' flag to specify a specific org. Run 'sf env list' to see a list of environments.

Examples for env create compute

Create a compute environment to run Salesforce Functions:

Connect the environment to a specific org:

Create an alias for the compute environment:

Usage

sf env create compute
[--json]
[-o CONNECTED-ORG]
[-a ALIAS]

Flags

--json
Optional

Format output as json.

Type: boolean
-o | --connected-org CONNECTED-ORG
Optional

Username or alias for the org that the compute environment should be connected to.

Type: option
-a | --alias ALIAS
Optional

Alias for the created environment.

Type: option

env create sandbox (Beta)

Create a sandbox org.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms (https://www.salesforce.com/company/legal/agreements/).

Note

Description for env create sandbox

There are two ways to create a sandbox org: specify a definition file that contains the sandbox options or use the --name and --license-type flags to specify the two required options. If you want to set an option other than name or license type, such as apexClassId, you must use a definition file.

Examples for env create sandbox

Create a sandbox org using a definition file and give it the alias "MyDevSandbox". The production org that contains the sandbox license has the alias "prodOrg".

Create a sandbox org by directly specifying its name and type of license (Developer) instead of using a definition file. Set the sandbox org as your default.

Usage

sf env create sandbox
[--json]
[-f DEFINITION-FILE]
[-s]
[-a ALIAS]
[-w WAIT]
[-i POLL-INTERVAL]
[--async]
[-n NAME]
[-c CLONE]
[-l LICENSE-TYPE]
[-o TARGET-ORG]
[--no-prompt]
[--no-track-source]

Flags

--json
Optional

Format output as json.

Type: boolean
-f | --definition-file DEFINITION-FILE
Optional

Path to a sandbox definition file.

The sandbox definition file is a blueprint for the sandbox. You can create different definition files for each sandbox type that you use in the development process. See <https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_sandbox_definition.htm> for all the options you can specify in the defintion file.

Type: option
-s | --set-default
Optional

Set the sandbox org as your default org.

Type: boolean
-a | --alias ALIAS
Optional

Alias for the sandbox org.

When you create a sandbox, the generated usernames are based on the usernames present in the production org. To ensure uniqueness, the new usernames are appended with the name of the sandbox. For example, the username "user@example.com" in the production org results in the username "user@example.com.mysandbox" in a sandbox named "mysandbox". When you set an alias for a sandbox org, it's assigned to the resulting username of the user running this command.

Type: option
-w | --wait WAIT
Optional

Number of minutes to wait for the sandbox org to be ready.

If the command continues to run after the wait period, the CLI returns control of the terminal to you and displays the "sf env resume sandbox" command you run to check the status of the create. The displayed command includes the job ID for the running sandbox creation.

Type: option
-i | --poll-interval POLL-INTERVAL
Optional

Number of seconds to wait between retries.

Type: option
--async
Optional

Request the sandbox creation, but don't wait for it to complete.

The command immediately displays the job ID and returns control of the terminal to you. This way, you can continue to use the CLI. To check the status of the sandbox creation, run "sf env resume sandbox".

Type: boolean
-n | --name NAME
Optional

Name of the sandbox org.

The name must be a unique alphanumeric string (10 or fewer characters) to identify the sandbox. You can’t reuse a name while a sandbox is in the process of being deleted.

Type: option
-c | --clone CLONE
Optional

Name of the sandbox org to clone.

The value of clone must be an existing sandbox in the same target-org.

Type: option
-l | --license-type LICENSE-TYPE
Optional

Type of sandbox license.

Type: option
Permissible values are: Developer, Developer_Pro, Partial, Full
Default value: Developer
-o | --target-org TARGET-ORG
Optional

Username or alias of the production org that contains the sandbox license.

When it creates the sandbox org, Salesforce copies the metadata, and optionally data, from your production org to the new sandbox org.

Type: option
--no-prompt
Optional

Don't prompt for confirmation about the sandbox configuration.

Type: boolean
--no-track-source
Optional

Do not use source tracking for this sandbox.

We recommend you enable source tracking in Developer and Developer Pro sandbox, which is why it's the default behavior. Source tracking allows you to track the changes you make to your metadata, both in your local project and in the sandbox, and to detect any conflicts between the two.

To disable source tracking in the new sandbox, specify the --no-track-source flag. The main reason to disable source tracking is for performance. For example, while you probably want to deploy metadata and run Apex tests in your CI/CD jobs, you probably don't want to incur the costs of source tracking (checking for conflicts, polling the SourceMember object, various file system operations.) This is a good use case for disabling source tracking in the sandbox.

Type: boolean

env create scratch (Beta)

Create a scratch org.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms (https://www.salesforce.com/company/legal/agreements/).

Note

Description for env create scratch

There are two ways to create a scratch org: specify a definition file that contains the options or use the --edition flag to specify the one required option. If you want to set options other than the edition, such as org features or settings, you must use a definition file.

You must specify a Dev Hub to create a scratch org, either with the --target-dev-hub flag or by setting your default Dev Hub with the target-dev-hub configuration variable.

Examples for env create scratch

Create a Developer edition scratch org using your default Dev Hub and give the scratch org an alias:

Specify the Dev Hub using its alias and a scratch org definition file. Set the scratch org as your default and specify that it expires in 3 days:

Usage

sf env create scratch
[--json]
[-a ALIAS]
[--async]
[-d]
[-f DEFINITION-FILE]
[-v TARGET-DEV-HUB]
[-c]
[-e EDITION]
[-m]
[-y DURATION-DAYS]
[-w WAIT]
[--api-version API-VERSION]
[-i CLIENT-ID]
[-t]

Flags

--json
Optional

Format output as json.

Type: boolean
-a | --alias ALIAS
Optional

Alias for the scratch org.

New scratch orgs include one administrator by default. The admin user's username is auto-generated and looks something like test-wvkpnfm5z113@example.com. When you set an alias for a new scratch org, it's assigned this username.

Type: option
--async
Optional

Request the org, but don't wait for it to complete.

The command immediately displays the job ID and returns control of the terminal to you. This way, you can continue to use the CLI. To resume the scratch org creation, run "sf env resume scratch".

Type: boolean
-d | --set-default
Optional

Set the scratch org as your default org

Type: boolean
-f | --definition-file DEFINITION-FILE
Optional

Path to a scratch org definition file.

The scratch org definition file is a blueprint for the scratch org. It mimics the shape of an org that you use in the development life cycle, such as acceptance testing, packaging, or production. See <https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_def_file.htm> for all the option you can specify in the definition file.

Type: option
-v | --target-dev-hub TARGET-DEV-HUB
Optional

Username or alias of the Dev Hub org.

Overrides the value of the target-dev-hub configuration variable, if set.

Type: option
-c | --no-ancestors
Optional

Don't include second-generation managed package (2GP) ancestors in the scratch org.

Type: boolean
-e | --edition EDITION
Optional

Salesforce edition of the scratch org.

The editions that begin with "partner-" are available only if the Dev Hub org is a Partner Business Org.

Type: option
Permissible values are: developer, enterprise, group, professional, partner-developer, partner-enterprise, partner-group, partner-professional
-m | --no-namespace
Optional

Create the scratch org with no namespace, even if the Dev Hub has a namespace.

Type: boolean
-y | --duration-days DURATION-DAYS
Optional

Number of days before the org expires.

Type: option
-w | --wait WAIT
Optional

Number of minutes to wait for the scratch org to be ready.

If the command continues to run after the wait period, the CLI returns control of the terminal to you and displays the job ID. To resume the scratch org creation, run the env resume scratch command and pass it the job ID.

Type: option
--api-version API-VERSION
Optional

Override the api version used for api requests made by this command

Type: option
-i | --client-id CLIENT-ID
Optional

Consumer key of the Dev Hub connected app.

Type: option
-t | --track-source
Optional

Use source tracking for this scratch org. Set --no-track-source to disable source tracking.

We recommend you enable source tracking in scratch orgs, which is why it's the default behavior. Source tracking allows you to track the changes you make to your metadata, both in your local project and in the scratch org, and to detect any conflicts between the two.

To disable source tracking in the new scratch org, specify the --no-track-source flag. The main reason to disable source tracking is for performance. For example, while you probably want to deploy metadata and run Apex tests in your CI/CD jobs, you probably don't want to incur the costs of source tracking (checking for conflicts, polling the SourceMember object, various file system operations.) This is a good use case for disabling source tracking in the scratch org.

Type: boolean
Default value: true

env delete

Delete an environment.

Description for env delete

You must include the name of the environment to delete using '--target-compute'. Run 'sf env list' to see a list of environments.

Running this command will prompt a confirmation. If you want to skip this confirmation, use the '--confirm' flag and the environment alias to skip confirmation.

Examples for env delete

Delete a compute environment:

Delete without a confirmation step:

Usage

sf env delete
[--json]
[-e TARGET-COMPUTE]
[--confirm CONFIRM]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option
--confirm CONFIRM
Optional

Confirmation name.

Type: option

env delete sandbox (Beta)

Delete a sandbox.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms (https://www.salesforce.com/company/legal/agreements/).

Note

Description for env delete sandbox

Specify a sandbox with either the username you used when you logged into it with "sf login", or the alias you gave the sandbox when you created it. Run "sf env list" to view all your environments, including sandboxes, and their aliases.

Examples for env delete sandbox

Delete a sandbox with alias my-sandbox:

Specify a username instead of an alias:

Delete the sandbox without prompting to confirm :

Usage

sf env delete sandbox
[--json]
[-o TARGET-ORG]
[-p]

Flags

--json
Optional

Format output as json.

Type: boolean
-o | --target-org TARGET-ORG
Optional

Sandbox alias or login user.

Type: option
-p | --no-prompt
Optional

Don't prompt the user to confirm the deletion.

Type: boolean

env delete scratch (Beta)

Delete a scratch org.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms (https://www.salesforce.com/company/legal/agreements/).

Note

Description for env delete scratch

Specify a scratch org with either the username you used when you logged into it with "sf login", or the alias you gave the scratch org when you created it. Run "sf env list" to view all your environments, including scratch orgs, and their aliases.

Examples for env delete scratch

Delete a scratch org with alias my-scratch-org:

Specify a username instead of an alias:

Delete the scratch org without prompting to confirm :

Usage

sf env delete scratch
[--json]
[-o TARGET-ORG]
[-p]

Flags

--json
Optional

Format output as json.

Type: boolean
-o | --target-org TARGET-ORG
Optional

Scratch org alias or login user.

Type: option
-p | --no-prompt
Optional

Don't prompt the user to confirm the deletion.

Type: boolean

env display

Display details about an environment.

Description for env display

Specify an environment with either the username you used when you logged into the environment with "sf login", or the alias you gave the environment when you created it. Run "sf env list" to view all your environments and their aliases.

Output depends on the type of environment. For example, scratch org details include the access token, alias, username of the associated Dev Hub, the creation and expiration date, the generated scratch org username, and more. Compute environment details include the alias, connected orgs, creation date, project name, and more.

Examples for env display

Display details about a scratch org with alias my-scratch-org:

Specify a username instead of an alias:

Specify JSON format and redirect output into a file:

Usage

sf env display
[--json]
[-e TARGET-ENV]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-env TARGET-ENV
Optional

Environment alias or login user.

Type: option

env list

List the environments you’ve created or logged into.

Description for env list

By default, the command displays active environments. For orgs, active means unexpired scratch orgs and orgs you’re currently logged into.

Output is displayed in multiple tables, one for each environment type. For example, the Salesforce Orgs table lists the non-scratch orgs you’re logged into, such as sandboxes, Dev Hubs, production orgs, and so on. Scratch orgs and compute environments get their own tables.

The two org tables show similar information, such as aliases, information about the org, and how you authorized (logged into) it, such as with a web browser or JWT. The scratch org table also shows the expiration date. For non-scratch orgs, the Username column refers to the user you logged into the org with. For scratch orgs it refers to the username that was generated for you when you created the scratch org. Your default scratch org or Dev Hub org is indicated with the "target-org" or "target-dev-hub" configuration variable, respectively, in the Config column.

The compute environment table shows the alias, information about the connected orgs, the project name, and more.

Use the table manipulation flags, such as --filter and --sort, to change how the data is displayed.

Run "sf env display" to view details about a specific environment.

Examples for env list

List all active environments:

List both active and inactive environments:

Filter the output to list only orgs you authorized using a web browser; "Auth Method" is the name of a column:

Display only the Aliases column and sort the aliases in descending order:

Don't truncate the displayed output and instead wrap text that's wider than your terminal:

Display only the table data, not the headers, in comma-separated value (csv) format:

Usage

sf env list
[--json]
[-a]
[--columns COLUMNS]
[--csv]
[--filter FILTER]
[--no-header]
[--no-truncate]
[--output OUTPUT]
[--sort SORT]

Flags

--json
Optional

Format output as json.

Type: boolean
-a | --all
Optional

Show all environments, even inactive ones.

Type: boolean
--columns COLUMNS
Optional

List of columns to display.

Type: option
--csv
Optional

Output in csv format [alias: --output=csv]

Type: boolean
--filter FILTER
Optional

Filter property by partial string matching.

Type: option
--no-header
Optional

Hide table header from output.

Type: boolean
--no-truncate
Optional

Don't truncate output to fit screen.

Type: boolean
--output OUTPUT
Optional

Format in which to display the output.

Type: option
Permissible values are: csv, json, yaml
--sort SORT
Optional

Column to sort by (prepend '-' for descending).

Type: option

env log (Beta)

Stream log output for an environment.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms (https://www.salesforce.com/company/legal/agreements/).

Note

Examples for env log

Stream log output:

Usage

sf env log
[--json]
[-e TARGET-COMPUTE]
[-n NUM]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Compute environment name to retrieve logs.

Type: option
-n | --num NUM
Optional

Number of lines to display.

Type: option

env log tail

Stream log output for an environment.

Examples for env log tail

Stream log output:

Usage

sf env log tail
[--json]
[-e TARGET-COMPUTE]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Compute environment name to retrieve logs.

Type: option

env logdrain add

Add log drain to a specified environment.

Description for env logdrain add

Both '--target-compute' and '--url' are required flags. '--url' should be a HTTP or HTTPS URL that can receive the log drain messages.

Examples for env logdrain add

Add a log drain:

Usage

sf env logdrain add
[--json]
[-e TARGET-COMPUTE]
[-l DRAIN-URL]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option
-l | --drain-url DRAIN-URL
Optional

Endpoint that will receive sent logs.

Type: option

env logdrain list

List log drains connected to a specified environment.

Examples for env logdrain list

List log drains:

List log drains as json:

Usage

sf env logdrain list
[--json]
[-e TARGET-COMPUTE]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option

env logdrain remove

Remove log drain from a specified environment.

Description for env logdrain remove

Both '--target-compute' and '--drain-url' are required flags.

Examples for env logdrain remove

Remove a logdrain:

Usage

sf env logdrain remove
[--json]
[-e TARGET-COMPUTE]
[-l DRAIN-URL]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option
-l | --drain-url DRAIN-URL
Optional

Log drain url to remove.

Type: option

env open

Open an environment in a web browser.

Description for env open

You can open the following types of environments in a web browser: scratch orgs, sandboxes, Dev Hubs, and production orgs. Run "sf env list" to view your environments and their aliases and login usernames.

Each of your environments is associated with an instance URL, such as https://login.salesforce.com. To open a specific web page, specify the portion of the URL after "<URL>/" with the --path flag, such as /apex/YourPage to open a Visualforce page.

Examples for env open

Open the Visualforce page /apex/StartHere in a scratch org with alias test-org:

View the URL but don't launch it in a browser:

Open the environment in the Google Chrome browser:

Usage

sf env open
[--json]
[-p PATH]
[-r]
[-e TARGET-ENV]
[--browser BROWSER]

Flags

--json
Optional

Format output as json.

Type: boolean
-p | --path PATH
Optional

Path to append to the end of the login URL.

Type: option
-r | --url-only
Optional

Display the URL, but don’t launch it in a browser.

Type: boolean
-e | --target-env TARGET-ENV
Optional

Login user or alias of the environment to open.

Specify the login user or alias that’s associated with the environment. For scratch orgs, the login user is generated by the command that created the scratch org. You can also set an alias for the scratch org when you create it.

For Dev Hubs, sandboxes, and production orgs, specify the alias you set when you logged into the org with "sf login".

Type: option
--browser BROWSER
Optional

Browser in which to open the environment.

You can specify that the environment open in one of the following browsers: Firefox, Safari, Google Chrome, or Windows Edge. If you don’t specify --browser, the environment opens in your default browser. The exact names of the browser applications differ depending on the operating system you're on; check your documentation for details.

Type: option

env resume sandbox (Beta)

Check the status of a sandbox creation, and log in to it if it's ready.

This feature is a Beta Service. Customers may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms (https://www.salesforce.com/company/legal/agreements/).

Note

Description for env resume sandbox

Sandbox creation can take a long time. If the original "sf env create sandbox" command either times out, or you specified the --async flag, the command displays a job ID. Use this job ID to check whether the sandbox creation is complete, and if it is, the command then logs into it.

You can also use the sandbox name to check the status or the --use-most-recent flag to use the job ID of the most recent sandbox creation.

Examples for env resume sandbox

Check the status of a sandbox creation using its name and specify a production org with alias "prodOrg":

Check the status using the job ID:

Check the status of the most recent sandbox create request:

Usage

sf env resume sandbox
[--json]
[-w WAIT]
[-n NAME]
[-i JOB-ID]
[-l]
[-o TARGET-ORG]

Flags

--json
Optional

Format output as json.

Type: boolean
-w | --wait WAIT
Optional

Number of minutes to wait for the sandbox org to be ready.

If the command continues to run after the wait period, the CLI returns control of the terminal window to you and returns the job ID. To resume checking the sandbox creation, rerun this command.

Type: option
-n | --name NAME
Optional

Name of the sandbox org.

Type: option
-i | --job-id JOB-ID
Optional

Job ID of the incomplete sandbox creation that you want to check the status of.

The job ID is valid for 24 hours after you start the sandbox creation.

Type: option
-l | --use-most-recent
Optional

Use the most recent sandbox create request.

Type: boolean
-o | --target-org TARGET-ORG
Optional

Username or alias of the production org that contains the sandbox license.

When it creates the sandbox org, Salesforce copies the metadata, and optionally data, from your production org to the new sandbox org.

Type: option

env resume scratch

Resume the creation of an incomplete scratch org.

Description for env resume scratch

When the original "sf env create scratch" command either times out or is run with the --async flag, it displays a job ID.

Run this command by either passing it a job ID or using the --use-most-recent flag to specify the most recent incomplete scratch org.

Examples for env resume scratch

Resume a scratch org create with a job ID:

Resume your most recent incomplete scratch org:

Usage

sf env resume scratch
[--json]
[-i JOB-ID]
[-r]

Flags

--json
Optional

Format output as json.

Type: boolean
-i | --job-id JOB-ID
Optional

Job ID of the incomplete scratch org create that you want to resume.

The job ID is the same as the record ID of the incomplete scratch org in the ScratchOrgInfo object of the Dev Hub.

The job ID is valid for 24 hours after you start the scratch org creation.

Type: option
-r | --use-most-recent
Optional

Use the job ID of the most recent incomplete scratch org.

Type: boolean

env var get

Display a single config variable for an environment.

Description for env var get

You must provide the '--target-compute' flag and the key to retrieve.

Examples for env var get

Get a config variable:

Usage

sf env var get
[--json]
[-e TARGET-COMPUTE]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option

env var list

List your environment's config vars in a table.

Description for env var list

Use the '--json' flag to return config vars in JSON format.

Examples for env var list

List config vars:

List in JSON format:

Usage

sf env var list
[--json]
[-e TARGET-COMPUTE]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option

env var set

Set a single config value for an environment.

Examples for env var set

Set a config value:

Usage

sf env var set
[--json]
[-e TARGET-COMPUTE]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option

env var unset

Unset a single config value for an environment.

Description for env var unset

Run 'sf env var list' to see a list of config values that can be unset.

Examples for env var unset

Unset a value:

Usage

sf env var unset
[--json]
[-e TARGET-COMPUTE]

Flags

--json
Optional

Format output as json.

Type: boolean
-e | --target-compute TARGET-COMPUTE
Optional

Environment name.

Type: option