Sub topic 8
Developing in a Sandbox with Change Tracking
This chapter covers how a developer or admin makes changes in a development environment while DevOps Center tracks them against a work item. It assumes you can create sandboxes, you know what metadata is, and you have read the earlier chapters on environments, pipelines and work items. The next chapter covers pulling and committing the tracked changes.
What change tracking does
DevOps Center does not watch your clicks. It relies on source tracking, a Salesforce feature that compares the current state of a sandbox's metadata with a baseline. When you save a change in a development environment, the org records it as a pending change. DevOps Center reads that list of pending changes and lets you attach them to the work item you are working on.
This has some consequences:
- Tracking is a property of the org, not of the work item. The org keeps one list of changes, and you decide which of them belong to which work item.
- Only metadata types that support source tracking appear in the list. Data, such as records, never appears.
- Changes made through the Setup UI, the Developer Console, the Salesforce CLI, or Code Builder are tracked in the same way.
Development environments in a DevOps Center pipeline are normally Developer or Developer Pro sandboxes, or scratch orgs where your team uses them. Source tracking is enabled by default on these sandbox types when they are created. A sandbox that existed before you adopted DevOps Center may not have source tracking enabled, so create a new one for the pipeline.
The development loop
For a single work item, the loop looks like this.
- Open the work item in DevOps Center and select your development environment. If you have not used it before, DevOps Center asks you to authenticate to the sandbox.
- Check that the sandbox is in sync with the work item's starting point (see the next section).
- Make changes in the sandbox, using whichever tools you prefer.
- Return to the work item and choose to pull changes. The list of pending changes appears.
- Select the changes that belong to this work item and commit them (covered in the next chapter).
Keeping the sandbox in sync
A development environment is useful only if its baseline matches the stage the work item will be merged into. Two situations cause trouble.
Starting from stale metadata
If other work items have been promoted since you last refreshed your sandbox, your sandbox does not contain their changes. You may edit a component that has since changed elsewhere. When your work item reaches review, the branches diverge and you face a conflict. A later chapter covers conflict resolution. The cheaper fix is to avoid the problem:
- Refresh or recreate the sandbox from the stage that your work items branch from.
- Keep work items small and short-lived, so the window for divergence is narrow.
- If the pipeline offers it, bring the latest changes from the stage into your work item before you start.
One sandbox, several work items
You can use one development environment for several work items. This is where careless tracking causes problems. The sandbox shows every pending change in one list, whether or not it belongs to the work item you have open. If you work on two features at once, the changes mix, and you must pick them apart when you commit.
A practical rule is one development environment per developer, and one active work item at a time. If you must switch, pull and commit the first work item's changes before you start the second.
Using tools to make changes
DevOps Center is tool-neutral for edits. The table compares the common ways to change a sandbox.
| Method | Good for | Watch out for |
|---|---|---|
| Setup UI | Admin changes such as fields, page layouts, flows, permission sets | Saving a layout can touch several related components at once |
| Developer Console | Quick Apex or Visual Force edits | Easy to edit the wrong sandbox if you have several orgs open |
| Code Builder or VS Code with Salesforce Extensions | Larger code changes and Lightning Web Components | Local files are not tracked until you deploy them to the sandbox |
| Salesforce CLI | Scripted or bulk changes | Deploy to the development sandbox, not to a stage |
The last two rows deserve emphasis. DevOps Center tracks changes in the org. If you edit Apex in a local project, nothing appears in DevOps Center until you deploy that code to the development sandbox. A deploy that succeeds registers the change as a pending change, and the change is then available to pull.
sf org login web --alias dev1
sf project deploy start --source-dir force-app/main/default/classes --target-org dev1Why one UI save can produce many changes
A single action in Setup can change more than one metadata component. Creating a custom field, for example, may also modify a page layout, a profile, or a permission set, depending on the options you pick. All of these appear as separate pending changes.
Review each item before you add it. Profiles and layouts are the usual source of surprises, because they are large files that many work items touch. If your work item has no reason to change the Admin profile, leave that change out. Prefer permission sets over profiles for new access, since they are smaller and conflict less often.
Reading the pending changes list
Each entry in the list identifies a component by name and type, with a status such as added, modified, or deleted. Use these points when you review it.
- A deleted entry means the component was removed in the sandbox. Committing it removes the component from the branch and, after promotion, from higher stages.
- A modified entry for a component you never opened can come from a side effect of another change, or from a baseline difference between the sandbox and the repository.
- A very large list on a fresh sandbox usually means the sandbox was not created from the pipeline's baseline. Stop and investigate before committing anything.
Keeping unwanted files out of the project
Local tooling files do not belong in a release. A .forceignore file at the project root tells the tooling which paths to skip.
# .forceignore
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**
.sfdx
.sfThe project file sfdx-project.json defines which directory holds source, so the repository, the sandbox and the CLI all agree on layout.
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "62.0"
}Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| No pending changes appear after an edit | Source tracking is off, or the edit was local only | Use a sandbox created with tracking enabled, and deploy local code to the org |
| Changes from another feature appear in the list | The sandbox is shared or was not cleaned between work items | Commit or discard the older changes first, and select only the relevant ones |
| The list has hundreds of entries | The sandbox baseline does not match the repository | Refresh the sandbox from the correct stage |
| A change you made is missing | The metadata type is not supported for tracking | Check the supported metadata list and move the change by another route |
Exercise
You are working on a work item that adds a custom field. After saving it, DevOps Center lists the new field, a page layout, and the System Administrator profile as pending changes. You did not intend to change the profile. What should you do, and why?
Show answer
Review the profile change before selecting anything. If the work item has no reason to change the profile, leave it out of the commit (or revert it in the sandbox). The field and the page layout are the real change. Profiles are large and often edited by several work items, so including one by accident raises the chance of a conflict and carries unreviewed access changes to later stages. If users need access to the field, grant it through a permission set that belongs to this work item.
Exercise
A teammate edits an Apex class in VS Code and tells you the change is "done", but nothing shows up as pending in DevOps Center. What is the most likely reason, and what is the fix?
Show answer
DevOps Center tracks changes in the sandbox, and a local file edit has not reached the org. The teammate needs to deploy the class to the development sandbox, for example with sf project deploy start --source-dir force-app/main/default/classes --target-org dev1. After a successful deploy, the change is registered as pending and can be pulled.