Use an Existing Access Token
When you authorize an org using the org login
commands, Salesforce CLI takes care of generating and refreshing all tokens, such as the access
token. But sometimes you want to run a few CLI commands against an existing org without going
through the entire authorization process. In this case, you provide the access token and URL of
the Salesforce instance that hosts the org to which you want to connect.
Almost all CLI commands that have the --target-org |
-o flag accept an access token. The only exception is org display user.
- Open a terminal (macOS and Linux) or command prompt (Windows).
-
To get the instance URL and access token for the org to connect to, run the org display command. See the values for the Access Token and Instance
Url keys.
sf org display --target-org myorg === Org Description KEY VALUE ─────────────── ─────────────────────────────────────────────── Access Token 00D8H0000007wprAQkAQAlOT5H (truncated for security) ... Instance Url https://creative-impala-20hx3-dev-ed.my.salesforce.com ...
-
Use config set to set the org-instance-url configuration variable. To set it locally,
run the command from a Salesforce DX project; to set it globally, use the --global flag.
sf config set org-instance-url=https://creative-impala-20hx3-dev-ed.my.salesforce.com --global
-
When you run the CLI command, use the org’s access token as the value for the --target-org flag rather than the org’s username. For
example:
sf project deploy start --source-dir <source-dir> --target-org 00D8H0000007wprAQkAQAlOT5H
Salesforce CLI doesn’t store the access token in its internal files. It uses it only for this CLI command run.