What's the main differences between unlocked & unmanaged packages?
As for me, the most important difference is that the unlocked package uses SFDX for development. So you, as a developer, could create a package, create a new version, promote, install to org within only SFDX. So it is possible to script all required actions, so that automate the process and use CI in the development of the package.
- 2-nd generation package
- requires enabled DevHub and Packaging feature on DevHub on an org
- uses SFDX and all its powerful instruments for development (like
sfdx force:source:pullCLI commands)
- source of truth is your version control system
- uses scratch orgs for development
- can have dependencies on other 2-nd gen packages
- first-generation package
- commonly uses Metadata API to develop components of the package
- source of truth is a developer org
- you need to manually add components to a package, upload new version from dev org by means of UI
Unlocked Packages are more like an advanced form of Managed Packages, not Unmanaged Packages. Many of the same differences exist for Unlocked Packages and Managed Packages as compared to Unmanaged Packages.
Unlocked Packages can be upgraded, like Managed Packages. Unmanaged Packages cannot be upgraded without uninstalling.
Unlocked Packages can be downgraded. Managed Packages and Unmanaged Packages cannot be downgraded.
Unlocked Packages can have dependencies on other packages, both Managed Packages and Unlocked Packages. Managed Packages cannot have dependencies on Unlocked Packages.
Unlocked Packages can have multiple packages in a single org, unlike Managed Packages, which each require their own org.
Managed Packages support Namespaces. Unlocked Packages may only exist in a Managed Package namespace, or in a null namespace, like Unmanaged Packages.
Unlocked Packages can delete metadata that is obsolete, unlike Managed Packages (with limited exceptions). Unlocked Packages can optionally not delete metadata that is obsolete, unlike Unmanaged Packages.
Source of Truth
Unlocked Packages are always sourced from local files, while Unmanaged Packages and Managed Packages always source from an org.
As you can see, Unlocked Packages are more of a hybrid between Managed Packages and Unmanaged Packages, leaning towards the Managed Package end of the feature spectrum. They are far more convenient than Unmanaged Packages for almost all use cases, except the obvious one-off "share the package with the others" scenario, and often more convenient than Managed Packages for non-ISVs (though they also help ISVs).
Hope You can find the answer on this FAQ You can also add up to this :
- Managed Packages always requires a namespace to distinguish the package on app exchange from other developer packages
- Managed packages restricts the removal of methods if the package is already released. Have a look at this
Also, Have a look at this extremely useful Stack Overflow Question