Newer Version Available
Track Changes Between the Project and the Sandbox (Beta)
As a beta feature, Source Tracking in Sandboxes is a preview and isn’t part of the “Services” under your master subscription agreement with Salesforce. Use this feature at your sole discretion, and make your purchase decisions only on the basis of generally available products and features. Salesforce doesn’t guarantee general availability of this feature within any particular time frame or at all, and we can discontinue it at any time. This feature is for evaluation purposes only, not for production use. It’s offered as is and isn’t supported, and Salesforce has no liability for any harm or damage arising out of or in connection with it. All restrictions, Salesforce reservation of rights, obligations concerning the Services, and terms for related Non-Salesforce Applications and Content apply equally to your use of this feature. You can provide feedback and suggestions for the Source Tracking in Sandboxes feature by posting in Collaboration or Ideas in the Trailblazer Community.
This feature is available in Developer and Developer Pro Sandboxes only.
For setup instructions, see the Salesforce DX Setup Guide.
If you're working in a scratch org instead of a sandbox, see Track Changes Between the Project and Scratch Org.
Set the Environment Variable for Tracking Changes by Multiple Users
These instructions set up source tracking for Developer and Developer Pro sandboxes where multiple users are making changes. We recommend a development model where each user makes changes in their own development sandbox, but we understand that sometimes multiple users share a development sandbox.
To configure source tracking in sandboxes, set the environment variable SFDX_ENABLE_MULTIUDX to true.
Authenticate Your Sandbox in Salesforce CLI
Authenticating your Developer or Developer Pro sandbox in the local Salesforce CLI lets them communicate through CLI commands without requiring additional credentials.
We've given the sandbox in this example the alias MyDevSandbox. To authenticate your sandbox in the CLI, run the following command.
You use the -r flag to override the default login URL (which is the URL for the production org) with the login URL for the sandbox. The sandbox in the example uses the alias MyDevSandbox.
The sandbox login page opens in a web browser. Log into the sandbox using your normal sandbox credentials, accept the authentication request, then close the browser.
Create a New Salesforce DX Project
Sandbox source tracking syncs against a local workspace to identify what's been changed in the sandbox. From a working directory, create a new Salesforce DX project that can serve as the standard of comparison. Let's call our new project MyControlProject.
You're now set up to have the sandbox org track changes you make there.
Display Sandbox Changes Identified by Source Tracking
Make a few configuration changes in the sandbox org, then go to the project directory (MyControlProject in the previous section) and display a list of the changes you just made. Remember, MyDevSandbox was the alias assigned to the sandbox that was authenticated in Salesforce CLI.
You see that a list of changes posted to output:
Pull Changed Source from the Sandbox to Your Project
When source tracking is enabled in a sandbox, pulling source from the sandbox to your local source directory moves only the files that changed:
Push Changed Source from Your Project to the Sandbox
If you make changes in a local environment or IDE and your sandbox is set up for source tracking, it's easy to synchronize the sandbox with the local environment. Push the local changes to the sandbox, and source tracking identifies which files have changes and automatically pushes only those files.
You can push local changes to a sandbox with source tracking enabled even if the changes are in a metadata source file that you retrieved to the local workspace. For example, let's say that you wanted to retrieve an ApexClass called MyApexClass to make some updates.
When you're ready to sync your local changes with the sandbox, you could use the force:source:deploy command, but you'd have the extra bother of explicitly specifying the files to deploy.
Instead, because your sandbox is set up for source tracking, a simple force:source:pushcommand automatically pushes only the changed files to the sandbox.
Tip: Let Source Tracking Help You Identify Change Set Components
If you're using change sets to migrate customizations, you can use the sfdx force:source:status command to help you identify which components need to be added to the change set. That way, when you're ready to build an outbound change set, you can use the sfdx force:source:status -u MyDevSandbox command to display a list of changed components.