Sub topic 2
Which orgs support source tracking
Source tracking is not available in every Salesforce org. Before you rely on "deploy only what changed", you need to know whether your target org supports it. This chapter assumes you have a Salesforce DX project with sfdx-project.json and a force-app directory. It also assumes the sf CLI is installed and you can authorize orgs. The previous chapter covered what tracking records. This one covers where it exists.
The short answer
Source tracking depends on the org type and on how the org was created or configured.
| Org type | Source tracking | Notes |
|---|---|---|
| Scratch org | Yes, by default | Can be turned off at creation time. |
| Developer sandbox | Yes, by default | Can be turned off at creation time. |
| Developer Pro sandbox | Yes, by default | Can be turned off at creation time. |
| Partial Copy sandbox | Not by default | Check Setup and the release notes for your release to see if you can enable it. |
| Full sandbox | Not by default | Same as Partial Copy. |
| Production org | No | Always requires explicit source selection. |
| Developer Edition org | No | Always requires explicit source selection. |
| Trial and other orgs | No | Treat these as untracked. |
Salesforce has widened sandbox support over several releases. Treat the table as the general rule and confirm the details for your org in the current Salesforce documentation.
Why only some orgs can track
Tracking needs help from the org itself. The org keeps a record of each metadata component change, and the CLI reads that record. This record is the org-side revision data that the next chapter explains. Salesforce runs that record only in orgs that are meant for active development. These are scratch orgs and developer-oriented sandboxes, where many people make frequent small changes.
Production orgs are different. They hold live data and live configuration, and changes are expected to arrive through deliberate deployments. Changes to production are not meant to be pulled down piece by piece. Full and Partial Copy sandboxes are large and are usually used for testing and staging, so the revision record has historically been left off.
The practical result is a split in your workflow:
- In a tracked org, the CLI works out what changed. You run
deploy startorretrieve startwith no source flags. - In an untracked org, you tell the CLI what to move. You name a directory, a list of metadata, or a manifest.
Scratch orgs
A scratch org is a temporary org created from a definition file. Source tracking is on by default, so this is the simplest place to learn the tracked workflow.
sf org create scratch --definition-file config/project-scratch-def.json --alias my-scratch --set-defaultThe --alias flag gives the org a short name you can use with --target-org. The --set-default flag makes it your default target org for the project, so you can leave out --target-org later. In this tutorial the examples pass --target-org explicitly so each command is clear on its own.
You can turn tracking off when you create the org, with the --no-track-source flag. You would do this when you plan to deploy a large, fixed package once and never retrieve changes. Skipping tracking can make creation and the first deploy lighter. Most developers should leave tracking on.
Scratch orgs expire. They have a duration of 1 to 30 days, and the default is 7. When an org expires, its tracking state expires with it. The tracking files left on your machine are then stale, and the sf org delete scratch command or a later cleanup removes them. Creating a new scratch org starts a fresh tracking history.
Developer and Developer Pro sandboxes
Developer and Developer Pro sandboxes are copies of your production metadata, without the production data in the Developer case. They support source tracking by default.
You create them with the sf org create sandbox command. It also accepts --no-track-source. As with scratch orgs, the default is to track.
An important detail is that tracking begins when the sandbox is created or refreshed. A sandbox starts with the metadata it was copied from, and the org-side record starts from that point. Changes made before the copy are not listed as changes. The first retrieve after creation therefore does not pull down your whole org. It pulls down only what someone changes afterward.
If a sandbox is refreshed, you get a new starting point. Your local tracking files from before the refresh no longer describe the new org. The chapter on resetting and clearing tracking covers how to handle that.
Partial Copy and Full sandboxes
These sandbox types are meant for integration testing, user acceptance testing, and staging. Source tracking is not on by default for them. Salesforce has made tracking available for these types in some cases, and it may require an option to be selected when the sandbox is created or an admin setting to be enabled. This changes between releases, so check the current documentation and your org's Setup pages instead of assuming.
Even when you can enable tracking for these sandboxes, you should ask whether you want it. These orgs are rarely a place where individual developers make many small configuration edits. They usually receive deployments of finished work. For that, an explicit manifest or a package-based deploy is often a better fit than tracking.
Production and Developer Edition orgs
Production orgs do not support source tracking. Developer Edition orgs and trial orgs do not either. In all of these, the CLI cannot compute what changed, so you must tell it what to deploy or retrieve.
sf project deploy start --target-org my-sandbox --source-dir force-app/main/default/classes
sf project deploy start --target-org my-sandbox --metadata ApexClass:MyClass
sf project deploy start --target-org my-sandbox --manifest manifest/package.xmlThe three commands show three ways to select source:
--source-dirtakes a path. Everything under that path is deployed.--metadatatakes a type and name, such asApexClass:MyClass. Only that component is deployed.--manifesttakes apackage.xmlfile that lists the components. This is the usual approach for repeatable, reviewed deployments.
The example uses a sandbox alias, but the same flags work against any org. A later chapter in this tutorial covers the untracked workflow in full. For now, the key point is that these flags are how you work when tracking is not available.
How to tell whether your org is tracked
The CLI does not print a simple "tracking: on" label in sf org list. You find out in other ways.
- Think about how the org was created. Scratch orgs and Developer or Developer Pro sandboxes created without
--no-track-sourceare tracked. - Try a preview.
sf project deploy preview --target-org my-scratchlists the local changes that would deploy. In an untracked org, the command cannot compute that list and reports an error or asks for source flags. - Look at your project. Tracked orgs create tracking files under the
.sfdirectory in your project, in a folder named for the org. A later chapter explains those files.
Common mistakes
- Assuming every sandbox tracks. A Full sandbox that you authorized last month probably does not. Check before you depend on it.
- Authorizing an org that was created elsewhere. Authorizing an existing org with
sf org login webdoes not change whether the org tracks. It either supports tracking or it does not, based on how it was created. Tracking files appear on your machine only when the org supports tracking. - Using
--no-track-sourceby habit. It saves time at creation but removes the main benefit of the workflow. Use it only when you understand what you give up. - Reusing tracking state after a refresh. A refreshed sandbox is a new starting point. Old local tracking data can cause confusing results.
Do not run a blind deploy against production to "see what changes". Production has no tracking, so a deploy sends exactly what you select. Use `--dry-run` or a validation deploy first, and review what you are sending.Choosing the right approach
Use tracking when the org is yours, changes often, and receives edits from several places, including point-and-click changes in Setup. Use explicit source selection when you are promoting reviewed work to a shared or critical org. Many teams use both. Developers work in tracked scratch orgs or Developer sandboxes. Their finished work moves up through untracked orgs with a manifest, driven by version control and a pipeline.
Exercise
You are told to deploy a change to a Full sandbox that was created without any special options, and to run sf project deploy start --target-org uat with no source flags. Why might this fail, and what should you run instead?
Show answer
A Full sandbox does not track source by default, so the CLI has no record from which to compute local changes. Name the source explicitly, for example sf project deploy start --target-org uat --source-dir force-app/main/default/classes, --metadata ApexClass:MyClass, or --manifest manifest/package.xml.
Exercise
You create a scratch org with --no-track-source. Which workflow do you now use to deploy your project, and which one would you have used without that flag?
Show answer
With --no-track-source the org is untracked, so you use --source-dir, --metadata, or --manifest. Without the flag, a scratch org is tracked, so sf project deploy start with no source flags deploys only your local changes.