Sub topic 2
Unlocked, Unmanaged and Managed Packages Compared
This chapter assumes you know basic Salesforce metadata (objects, fields, Apex classes, permission sets) and have used the Salesforce CLI with scratch orgs. You should also be comfortable with Apex tests and code coverage.
Why the package type matters
Salesforce offers several ways to move metadata between orgs. Each one answers three questions differently. Is the metadata versioned? Can you upgrade it in place? Who can edit it after installation? Picking the wrong type is hard to undo, because a package's type is fixed when you create it.
The three package types
An unmanaged package is a bundle of metadata with no version history. Once installed, the components are copied into the target org as ordinary metadata. Nothing links them back to the package, so you can't upgrade or remove them as a group. Unmanaged packages suit one-off sharing of templates or samples.
A managed package is built for distribution, usually by ISVs (independent software vendors) selling through AppExchange. It always has a namespace. The vendor can upgrade it, and the code is hidden from subscribers. Subscribers cannot edit most of its components. It needs a managed-package build process and the vendor's own packaging org setup.
An unlocked package is versioned, upgradeable metadata for your own organisation. The source stays visible and, in some cases, can be edited in the target org. Namespaces are optional. You build it from source control with the CLI, and you can install it into sandboxes and production.
Comparison
| Feature | Unmanaged | Unlocked | Managed |
|---|---|---|---|
| Versioned | No | Yes | Yes |
| Upgradeable in place | No | Yes | Yes |
| Namespace | No | Optional | Required |
| Code visible to installer | Yes | Yes | Hidden |
| Typical use | One-off sharing | Internal modularisation | Commercial distribution |
| Created from | Org UI | Dev Hub and CLI | Packaging org or Dev Hub |
Change sets for comparison
A change set is a point-in-time deployment between connected orgs. It has no version number, no dependency checking, and no source-control link. You can't tell later which components belong together. Unlocked packages replace this with a versioned artefact that you can rebuild, test, and install in any org.
How the types relate
Common mistakes
- Treating unmanaged as a first step toward unlocked. Installing an unmanaged package copies the metadata into the org. It does not create a package you can later upgrade.
- Using managed packages for internal work. The namespace and code protection add effort and constraints that internal teams rarely need.
- Assuming unlocked means unrestricted. Unlocked packages still have rules. For example, you can't package every metadata type, and you must meet the coverage rules covered in later chapters.
Exercise
Your team wants to split an internal org's metadata into versioned units that can be upgraded in production, with no need to hide the source. Which package type fits, and why not unmanaged?
Show answer
An unlocked package fits. It is versioned and upgradeable, and the source remains visible. An unmanaged package has no version history and its components become ordinary org metadata after installation, so it can't be upgraded or removed as a group.