Sub topic 6
Project-level settings: sourceApiVersion, sfdcLoginUrl, namespace, name
This chapter covers the four top-level keys in sfdx-project.json that sit beside packageDirectories. It assumes you can read JSON, have the sf CLI installed, and have already generated a project. These keys apply to the whole project, not to one package directory.
The four settings at a glance
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"name": "my-project",
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}| Key | What it controls | Typical value |
|---|---|---|
| `name` | A label for the project | `my-project` |
| `namespace` | The namespace prefix of the packages you build | `""` (empty) |
| `sfdcLoginUrl` | The login host used when you authorize an org | `https://login.salesforce.com` |
| `sourceApiVersion` | The metadata API version for source operations | `61.0` |
sourceApiVersion
sourceApiVersion sets the API version the CLI uses when it deploys, retrieves, and converts source. It is a string such as "61.0", not a number.
- If you omit it, the CLI falls back to the API version of the org you are working against. The same project can then behave differently in different orgs.
- Setting it pins the behavior. Metadata types and fields that exist only in a newer version are not available to a project pinned to an older one.
- A value newer than the target org supports causes deploys to fail.
You can override the version for a single command with the --api-version flag where the command supports it. Change the project value only when you intend to adopt newer metadata features.
sfdcLoginUrl
sfdcLoginUrl is the login URL the CLI uses by default for sf org login web. The generated value is the production login host.
Change it when your orgs are not on that host. For a sandbox, use https://test.salesforce.com. For a My Domain org, you can use the My Domain URL.
sf org login web --alias my-sandbox --instance-url https://test.salesforce.comThe --instance-url flag overrides the project value for that one login. Scratch orgs do not use this setting for creation, because sf org create scratch authorizes the new org itself.
namespace
namespace is the namespace prefix of the packages you build from this project. Most projects leave it empty, as the generated file does.
- Set it only if you own a registered namespace and it is linked to your Dev Hub.
- When it is set, scratch orgs created from the project use that namespace.
- A wrong or unlinked namespace is a common reason for package creation and scratch org errors.
Do not set a namespace just to make names look tidy. Once packages are created with one, it is difficult to undo.
name
name is a human-readable project name. The generator fills it in from the --name flag. The CLI does not use it to find files or to identify orgs, so renaming it has no effect on deploys or retrieves. Keep it matching the repository name so it is easy to recognize.
How the CLI applies these settings
Common mistakes
- Writing
"sourceApiVersion": 61as a number. Use the string"61.0". - Pinning an API version higher than the org supports, then seeing deploy errors.
- Leaving
sfdcLoginUrlon the production host and wondering why a sandbox login fails. - Setting
namespaceto a value not linked to the Dev Hub.
Exercise
Your team deploys to a sandbox, and you want sf org login web to default to the sandbox login host. You also want deploys to use API version 62.0 regardless of the org. Which two keys do you change, and to what values?
Show answer
Set "sfdcLoginUrl": "https://test.salesforce.com" and "sourceApiVersion": "62.0". The API version must be a string, and the org must support version 62.0 or deploys will fail.