Sub topic 4
Managed versus unmanaged packages
A package is the container Salesforce uses to ship an app's components to your org. Whether the container is managed or unmanaged decides who can change the app's code, how updates reach you, how easily you can remove it, and how much you can inspect before you trust it. This chapter covers those differences so you can judge a package type before you install.
This chapter assumes you can find Installed Packages in Setup and tell a sandbox from production. It also assumes you know what custom objects, Apex classes, and permission sets are. You don't need to have built a package yourself.
What a package is
A package bundles metadata such as custom objects, fields, Apex classes, Lightning components, flows, and permission sets. When you install it, Salesforce creates those components in your org. Every installable version has an ID that starts with 04t. You use that ID in the install command.
The two main types differ in one way. A managed package keeps its identity after installation. An unmanaged package dissolves into your org.
Managed packages
A managed package belongs to a namespace, a short unique prefix the publisher registers. Every component the publisher creates carries that prefix, so a custom object might appear as acme__Invoice__c and a field as acme__Status__c. The prefix has three effects:
- Components cannot collide with your own names.
- You can see which components came from the package.
- Salesforce can track the package as one unit, so it can upgrade or remove it cleanly.
What you get
- Upgrades. The publisher releases new versions, and you install them over the existing version. Your data and your own customizations outside the package are kept.
- Intellectual property protection. The publisher's Apex source is hidden from you. You see class names and the global interface, not the logic.
- A clear boundary. You can list the package's components, see its dependencies, and uninstall it as a unit.
- No effect on your Apex code size limit. Managed Apex does not count against your org's limit on Apex code characters. Unmanaged Apex does.
- Licensing. Publishers can use the License Management App to limit seats, run trials, and expire access. Chapter 10 covers this.
What you give up
- Limited editing. You cannot change released components in the package. You can usually change a small set of properties, such as a field label or a page layout assignment.
- Limited code inspection. You cannot read the Apex to check what it does. You have to rely on other evidence: the Security Review, the listed permissions, the external connections the package requests, and your own testing.
- Dependency lock-in. If your own flows, reports, or code reference package components, you cannot uninstall the package until you remove those references.
Managed beta versus released
A managed package version is either beta or released. Publishers can install beta versions only in sandboxes and developer orgs, and they can delete them. Released versions are permanent. Salesforce lets you upgrade only between released versions. A listing that only offers a beta version is not ready for production use.
Unmanaged packages
An unmanaged package is a one-time copy. After installation the components belong to your org, with no namespace and no link back to the publisher. You can open and edit the Apex, change the objects, and delete what you don't need.
What you get
- Full visibility. You can read every line of Apex and every flow before and after you install. This is the strongest vetting position available to you.
- Full control. You can adapt the components to your org.
What you give up
- No upgrades. The publisher cannot push a new version. If they send a new package, installing it can overwrite components that share the same names, including ones you customized.
- No clean removal. Salesforce no longer treats the components as one unit. To remove them you delete each component yourself, and dependencies can block the deletes.
- No licensing. There is no seat control or expiry.
- Code size cost. The Apex counts toward your org's code limit.
- Your maintenance burden. Once you edit the code, you own it, including bugs and any security flaws.
Unmanaged packages are common for sample code, templates, and accelerators that you are meant to adapt. Most commercial apps on AppExchange are managed packages. If a commercial product ships as unmanaged, ask the publisher how they plan to support updates.
Comparing the two
| Property | Managed | Unmanaged |
|---|---|---|
| Namespace prefix | Yes | No |
| Publisher can push upgrades | Yes | No |
| You can read the Apex | No (hidden) | Yes |
| You can edit components | Only a few properties | Yes |
| Counts against your Apex code limit | No | Yes |
| Uninstall as one unit | Yes, if nothing depends on it | No, delete components one by one |
| License management | Yes | No |
| Typical use | Commercial apps | Templates and sample code |
Second-generation packaging and unlocked packages
The types above are first-generation (1GP) packaging terms. Publishers now build many managed packages as second-generation managed packages (2GP), which are created with Salesforce DX and the sf CLI. From the subscriber's side a 2GP managed package behaves like a 1GP one: it has a namespace, hidden Apex, and upgrades. The differences are in how the publisher builds and versions it.
You may also meet unlocked packages. They are usually used by an organization to deploy its own metadata, not to sell apps. Their components are editable, and they have no namespace requirement. Treat an unlocked package from an outside vendor like an unmanaged one for vetting purposes, because you can read its source.
Package type and vetting
The package type changes what evidence you can collect, as the diagram shows.
For a managed package, you cannot inspect the code, so the other evidence carries more weight. Check the publisher's Security Review status, the permissions the package asks for, and the external hosts it contacts. Then watch its behavior in a sandbox.
For an unmanaged package, the code is there to read. Look for:
- Callouts to external hosts, such as
Http,HttpRequest, or named credentials. - Code declared
without sharing, which ignores the running user's record access. - Hard-coded credentials or endpoints.
- Triggers on standard objects, which can change how your existing processes behave.
Do this review before you install. Once the components are in the org, you may have to untangle them one by one.
Recognizing the type in your org
In Setup, open Installed Packages. Managed packages show a publisher and a namespace prefix. Unmanaged packages show the package name and no namespace.
From the CLI, list what is installed:
sf package installed list --target-org my-sandboxThe output includes the package name, namespace, and version number. An empty namespace column is a sign of an unmanaged or unlocked package. Be careful with this check, because an empty column can also mean the item is a package you built yourself.
Component names tell you the same thing. A custom field acme__Region__c belongs to the managed package with the namespace acme. A field Region__c belongs to your org or to an unmanaged package. When you review a sandbox after installation, look for new components without a prefix. They may be unmanaged components that now sit alongside your own.
Installing and the package type
You install both types with the package version ID. The install command from earlier in this tutorial applies to both:
sf package install --package 04tXXXXXXXXXXXXXXX --target-org my-sandbox --security-type AdminsOnly --wait 10Replace the placeholder with the 04t ID from the listing. The --security-type AdminsOnly option limits access to administrators, so you grant access to other users on purpose. Chapter 7 covers the install options in full.
For a managed package, installation puts the whole package under its namespace. For an unmanaged package, installation copies the components into your org, and the same command gives you no cleanup path later. This is why the sandbox trial matters most for unmanaged packages. A sandbox can be refreshed or discarded, and production cannot.
Common errors and gotchas
- Assuming Security Review applies to everything you install. The review covers apps the publisher submits through the AppExchange program. A package that someone sends you by direct link may never have been reviewed. Chapter 3 covers the limits of the review.
- Installing a beta version in production. Beta versions cannot be installed in production. If someone gives you a link that works only in a sandbox, check whether the version is still beta.
- Reinstalling an unmanaged package to "update" it. The new copy can overwrite components you changed. Compare the contents first and back up the metadata you edited.
- Editing unmanaged components without tracking changes. After you edit them, you can no longer tell which behavior came from the publisher and which from you.
- Blocking your own uninstall. If you reference a managed field in a flow, report, or validation rule, Salesforce stops the uninstall until you remove the reference. Document which of your own components depend on package components.
- Forgetting data loss on uninstall. Uninstalling a managed package deletes its custom objects and the data in them. Salesforce offers to export the package data first, and you should accept the export. Deleted data stays in the recycle bin for a limited time, but do not rely on it.
- Treating an empty namespace as proof of safety. An unmanaged package is easy to read, but only if you actually read it.
A decision checklist
Before you install, answer these questions:
- Is the package managed, unmanaged, or unlocked? Where does the listing say so?
- If it is managed, is the version released, and has the publisher passed the Security Review?
- If it is unmanaged, have you read the Apex, flows, and triggers for callouts,
without sharingclasses, and hard-coded secrets? - How will you receive updates? Through publisher upgrades, or by manually comparing and reinstalling?
- How will you remove it? As one unit, or component by component?
- Which of your own components will depend on it?
Write the answers down with the package ID. They become part of your rollback plan.
Exercise
A vendor sends you a link to install a package that has no namespace prefix on its components. List two things you can check in a sandbox before you install in production that you could not check for a managed package, and one extra risk this package type carries.
Show answer
You can read the Apex classes and triggers, and you can read the flows and metadata. For example, you can look for external callouts, without sharing classes, and hard-coded credentials. The extra risk is that there is no clean upgrade or uninstall path. You must delete components one at a time, and a later reinstall can overwrite your edits.
Exercise
You run sf package installed list and see a package with the namespace acme. Your team has a flow that references acme__Region__c. What happens if you try to uninstall the package, and what should you do first?
Show answer
Salesforce blocks the uninstall because your flow depends on a package component. First remove or change the reference in the flow. Also export the package data when Salesforce offers it, because uninstalling a managed package deletes its custom objects and their data.
Exercise
A publisher offers only a beta version of a managed package. Can you install it in production? What should you do instead?
Show answer
No. Beta versions of managed packages can be installed only in sandboxes and developer orgs. Ask the publisher for a released version, and test the beta in a sandbox if you want to evaluate it in the meantime.