Sub topic 1
What Source Tracking Is and Why It Matters
Prerequisites
Assume you know basic Salesforce DX project structure, have sf installed, and have authorized an org. You should also recognize metadata such as Apex classes and custom objects.
What Source Tracking Is and Why It Matters
Source tracking records metadata changes on both sides of a Salesforce project:
- The local project records changes in your files.
- The org records changes made through Setup, the Salesforce web interface, or other tools.
The Salesforce CLI compares these records. It can then deploy only local changes or retrieve only org changes. This reduces accidental overwrites and makes short feedback cycles easier.
Which Orgs Support Source Tracking
Scratch orgs are designed for source tracking. Create one with a definition file:
sf org create scratch --definition-file config/project-scratch-def.json --alias my-scratch --set-defaultSome sandboxes support source tracking when the required Salesforce features and setup are enabled. Production orgs and many other org types do not. With an untracked org, the CLI cannot calculate differences automatically. You must select a source directory, metadata name, or manifest.
How the CLI Knows What Changed
For a tracked org, the CLI compares the current local files and org metadata with earlier synchronized revisions. A local edit appears as a local change. A change made in the org appears as an org change. Before moving anything, preview both directions:
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchA conflict occurs when both sides changed the same component after the last synchronization. Review the preview before choosing which version should win.
Where Tracking State Lives on Your Machine
Salesforce CLI stores project tracking information in the project’s .sf directory. This state contains local snapshots and synchronization details. Do not treat these files as source code. Avoid editing or deleting them manually while work is active.
Keeping Files Out of Tracking with `.forceignore`
A .forceignore file lists files that the CLI skips during source operations:
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**Use it for editor settings, generated files, or tests that should not be synchronized as metadata.
Exercise
Why can the CLI deploy only some local components in a tracked scratch org?
Show answer
It compares the current project with stored tracking revisions and selects the components that changed.