Sub topic 1
The problem: one big org, one big deployment
This chapter describes what goes wrong when all of an org's metadata is treated as one undivided unit. It also introduces the idea that unlocked packages address. It is the first chapter of the tutorial, so it contains no package commands yet. It builds the vocabulary and the reasoning that the later chapters rely on.
Prerequisites
This chapter assumes you already know the following:
- Basic Salesforce metadata concepts: custom objects, fields, Apex classes, flows and permission sets.
- Salesforce DX basics: what a scratch org is and how to run commands with the Salesforce CLI.
- Git and source-driven development: committing metadata to a repository and merging branches.
- Apex tests and code coverage: how test classes run and what a coverage percentage means.
You do not need a Dev Hub or any package experience yet.
How orgs grow into one big deployment
A new org starts small. A few objects, some Apex and a handful of page layouts are easy to reason about. Over several years, many teams add to it. Administrators build flows and validation rules. Developers add triggers, Lightning components and integrations. Consultants add whole feature sets for projects that later change hands.
Nothing in the platform forces these additions into groups. Every component sits in one flat namespace of metadata, and the org itself is the only container. As a result, the org becomes the unit of everything:
- The unit of deployment. A release moves a bundle of changes from a sandbox to production.
- The unit of ownership. Nobody can say which team owns a given Apex class, because the org does not record it.
- The unit of testing. Production deployments run Apex tests across the whole org unless you specify otherwise.
- The unit of history. The only record of what changed, and why, lives in source control, if it was kept there at all.
This structure is often called a monolith. The word describes a system where every part is built, tested and released together, so a change to one part carries the risk of the whole.
What goes wrong
The problems below appear gradually. Each one is small at first and becomes expensive as the org grows.
Hidden dependencies
Metadata components reference each other. An Apex class reads a custom field. A flow calls an Apex action. A page layout shows a related list. A permission set grants access to all of them. In a flat org, these references are not declared anywhere you can inspect. You discover them when a deployment fails with an error such as "Field does not exist" or when a deletion is blocked because something still uses the component.
Over time, dependencies form in both directions. The sales code uses a service desk field, and the service desk code uses a sales utility class. That circular pattern makes it impossible to change either area safely on its own.
Deployments that carry too much
When one team finishes a feature, the deployment often includes unrelated changes that happened to be merged at the same time. If one of those changes fails validation, the whole release stalls. Teams respond by freezing releases or by batching more changes into each one, which makes each release larger and riskier.
Change sets, the classic tool for moving changes between connected orgs, add to the problem. A change set is a manually selected list of components. It does not carry a version number, it does not know what the target org already contains, and it cannot express that one set must be installed before another. Selecting components by hand also makes it easy to miss one, and the omission shows up only at deployment time.
Test and coverage friction
Salesforce requires at least 75% Apex code coverage across the org to deploy Apex to production. In a monolith, coverage is a shared number. One team with weak tests can drag down the figure for everyone, and a team with strong tests cannot protect itself from that. Running all tests also takes longer as the org grows, so feedback slows down.
No clear ownership or lifecycle
Without boundaries, retiring a feature is hard. The team that built a feature two years ago may have moved on, and the components remain with no record of which ones belong together. Cleanup requires someone to trace each component by hand. Most teams decide the risk is too high and leave the old metadata in place, so the org only grows.
Weak environment parity
Developers want a scratch org that looks like production, but a flat org gives no way to build one except by deploying everything. Large deployments to a scratch org are slow and fragile. Developers then work in sandboxes that drift from each other, and a feature that works in one environment fails in the next.
What a better structure looks like
The problems above share a cause: the org has no intermediate unit between a single component and the entire org. A more useful structure groups related components into units that have:
- A name and an owner, so responsibility is clear.
- A version, so you can say exactly which build is installed in an org.
- Declared dependencies, so the order of installation is explicit and checked.
- Their own tests, so coverage and validation apply to the unit.
The diagram compares the two models.
Salesforce provides this intermediate unit as a package. A package is a container for metadata that you build into a versioned artifact. Unlocked packages are one kind of package, and later chapters cover how they differ from unmanaged and managed packages.
What unlocked packages change
The sections above describe pain points. Unlocked packages address them in these ways:
| Problem in a monolithic org | How an unlocked package helps |
|---|---|
| Components have no declared grouping | Each package directory in your project lists its own metadata |
| Dependencies are discovered at deploy time | Dependencies between packages are declared and checked when you build a version |
| Releases carry unrelated changes | You release one package version at a time |
| Nobody can say what is installed | Each org records the package versions installed in it |
| Coverage is shared across teams | Package version creation can check coverage for that package alone |
| Old features are hard to remove | A package can be uninstalled as a group |
Two points need care, because they surprise people who expect packages to fix everything.
First, packaging does not remove dependencies. It makes them visible and forces you to declare them. If your design has circular references, you must still resolve them, because package dependencies cannot be circular.
Second, packages move the source of truth to your repository. An unlocked package is built from source files in version control. Editing the packaged components directly in a production org works against that model, because the next installation can overwrite the change.
Seeing the problem in your own org
You can test how monolithic your org is before you learn any package commands. Pull the metadata into a project and look for the symptoms.
The following Bash script counts Apex classes and flows in a source-format project, and flags classes that reference more than one business prefix. It assumes your custom objects use a prefix such as Sales_ or Support_. Adjust the prefixes to match your naming.
#!/usr/bin/env bash
set -euo pipefail
SRC="${1:-force-app}"
echo "Apex classes: $(find "$SRC" -name '*.cls' | wc -l)"
echo "Flows: $(find "$SRC" -name '*.flow-meta.xml' | wc -l)"
echo
echo "Classes that mention both Sales_ and Support_ names:"
while IFS= read -r file; do
if grep -q 'Sales_' "$file" && grep -q 'Support_' "$file"; then
echo " $file"
fi
done < <(find "$SRC" -name '*.cls')Run it with bash check-coupling.sh force-app. Each file it lists is a candidate cross-domain dependency. A long list suggests that any future package boundary will need work first. A short list suggests the domains are already fairly separate. This is a rough heuristic based on text matching and not a dependency analysis, so treat the result as a starting point for discussion.
Common misconceptions
- "Packages are only for ISVs." Independent software vendors do use packages to distribute products, but an internal team can use unlocked packages purely to organise its own org.
- "A package is a deployment tool." A package is a versioned artifact. Installing it deploys its contents, but the value is in the version, the declared dependencies and the repeatable result.
- "Packaging makes the org smaller." It does not. The same metadata exists, but it is grouped and named.
- "We can package everything at once." Some metadata types cannot be packaged, and tangled dependencies make a single large move risky. Incremental migration is the standard approach.
What comes next
The next chapter compares the three package types: unlocked, unmanaged and managed. It explains why unlocked packages suit internal teams that want flexibility and a clear change history. After that, you will set up a Dev Hub and define your first package directories.
Exercise
A team has one production org and one repository. Release builds often fail because a change from another team does not pass validation, and nobody can tell which Apex classes belong to which team. Name two of the problems from this chapter that this describes, and one property of a package that would help with each.
Show answer
The failing release is the "deployments that carry too much" problem. A version per package, released separately, lets one team ship without waiting for another. The unclear ownership is the "no clear ownership or lifecycle" problem. A package has a name and a defined set of metadata, so each class belongs to a named unit with an owner. Declared dependencies would also expose cross-team references that now surface only as deployment errors.
Exercise
Why does moving metadata into packages not remove circular dependencies between a Sales area and a Service area?
Show answer
Packaging only records and enforces dependencies. If Sales needs Service and Service needs Sales, neither package can be built first, because package dependencies cannot be circular. You must refactor the shared pieces, for example by moving them into a separate base package that both depend on.