Sub topic 2
Source control as the source of truth
This chapter assumes you know basic Git (branches, commits, pull requests, merges) and have used Salesforce sandboxes and metadata. It explains why DevOps Center treats a Git repository as the record of what your release contains, and how a Salesforce project is laid out inside that repository.
Why the repository is the source of truth
With change sets, the org holds the truth. A change set is a list of components that you upload from one org and deploy to another. It has no history you can diff, no review step, and no way to say which version of a component was approved. Two sandboxes can drift apart, and nobody can tell which one is right.
In a source-driven process, the Git repository holds the approved version of your metadata. Orgs are places where you build and test changes, and where you deploy releases. Each org should be reproducible from the repository. When an org and the repository disagree, the repository wins.
This gives you several things change sets do not:
- History. Every commit records who changed what and when.
- Review. A pull request lets another person approve a change before it moves on.
- Diffs. You can see the exact lines that changed in a Flow, a Apex class, or a profile.
- Recovery. You can return to an earlier commit if a release goes wrong.
- Parallel work. Branches let several people work on separate changes at the same time.
Source format and metadata
Salesforce can represent metadata in two formats.
- Metadata format is the older API format. Related components are often packed into large files, such as one XML file holding all the fields of an object.
- Source format splits those components into many small files. An object's fields, for example, each get their own file. Small files produce smaller diffs and fewer merge conflicts.
DevOps Center repositories use source format. A change to one custom field touches one file, so two people editing different fields on the same object rarely collide.
A typical layout looks like this:
my-release-repo/
sfdx-project.json
.forceignore
force-app/
main/
default/
classes/
flows/
lwc/
objects/
Account/
fields/
validationRules/
permissionsets/The project file
The sfdx-project.json file at the repository root tells Salesforce tooling where your source lives and which API version to use.
{
"packageDirectories": [
{ "path": "force-app", "default": true }
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "62.0"
}packageDirectorieslists the folders that hold your source. The folder markeddefaultis where new components are placed.namespaceis empty unless you build a namespaced managed package.sfdcLoginUrlis the login endpoint the CLI uses. Change it only for special cases such as a My Domain login.sourceApiVersionsets the API version used when source is retrieved and deployed.
If the file is missing or points to a folder that does not exist, tooling cannot find your metadata. Check this file first when a pipeline cannot see your components.
Keeping the repository clean
Not every file in a project folder belongs in a deployment. Editor settings, test harnesses, and caches should stay out. A .forceignore file lists paths that Salesforce tooling skips when it retrieves or deploys source. It uses patterns like .gitignore.
# .forceignore
**/jsconfig.json
**/.eslintrc.json
**/__tests__/**
.sfdx
.sfBranches in the pipeline
DevOps Center maps pipeline stages to branches. A stage is a step on the way to production, such as Integration, UAT, or Staging. Each stage has its own branch, and promoting a change means merging it into the next stage's branch and deploying that branch to the stage's org.
Each work item gets its own branch, created from the first stage's branch. You commit changes there, review them through a pull request, and merge them forward.
Because each stage is a branch, you can ask Git what a promotion would carry. This command lists commits that have reached UAT but not yet main:
git fetch origin
git log --oneline origin/main..origin/UATThe A..B range means "commits reachable from B that are not reachable from A". If the output is empty, nothing is waiting to move from UAT to main. Run git fetch first, or you compare against stale local copies of the remote branches.
Edge cases and common errors
Org changes with no commit. If someone edits an org directly, the repository does not know. The next deployment from the repository can overwrite that edit, or the org drifts from the branch. Make changes through work items, and treat direct edits to shared orgs as a process violation.
Hotfixes made only in production. A fix made directly in production never reaches the branches, so the next release can undo it. Hotfixes must be brought back into the repository. A later chapter covers this.
Metadata that does not retrieve cleanly. Some metadata types have limited source tracking or cannot be retrieved in source format. The chapter on limits covers which types, and you should check a type before you build a process around it.
Large, noisy diffs. Profiles often produce big diffs because they list many unrelated settings. Prefer permission sets for access changes, since they diff cleanly.
Merge conflicts in XML. Source format reduces conflicts but does not remove them. Two people editing the same field file can still collide. Resolve these in Git, then continue the pipeline.
Checking a change outside DevOps Center
Because the repository is plain source, you can validate it with the Salesforce CLI. A validation-only deployment runs the checks against an org but saves nothing. This one runs all local tests against an org with the alias uat:
sf org login web --alias uat
sf project deploy start --source-dir force-app --target-org uat --dry-run --test-level RunLocalTests--dry-run makes the deployment validation-only. --test-level RunLocalTests runs every test in your org except those from installed managed packages. This is useful before you promote a change, since a failure here would also fail in the pipeline.
Summary
- The repository holds the approved version of your metadata. Orgs are built from it.
- DevOps Center uses source format, which gives small files and smaller diffs.
sfdx-project.jsonlocates the source, and.forceignorekeeps tooling files out of deployments.- Each pipeline stage corresponds to a branch, and promotion merges forward through those branches.
- Changes made outside the repository are the main way orgs and source drift apart.
Exercise
A teammate edits a validation rule directly in your UAT org to fix an urgent problem, and does not commit it. Two days later, a promotion deploys the UAT branch to that org. What is likely to happen to the edit, and why? What should the teammate have done?
Show answer
The edit is likely to be overwritten or lost, because the UAT branch does not contain it, and the repository is the source of truth for the deployment. The teammate should have made the change through a work item in a development environment, committed it to the work item branch, and sent it through a pull request and promotion. If it was a true emergency, the fix must be brought back into the repository right afterward.
Exercise
You run git log --oneline origin/main..origin/UAT and get five commits. What does that tell you, and what should you do before trusting the result?
Show answer
It means five commits are on the UAT branch that are not yet on main, so a promotion from UAT to main would carry those five changes. Before trusting it, run git fetch origin so your local view of the remote branches is current.