Ask Krrish Contact
Home
Developer & Admin
Apex Triggers Mastery Asynchronous Apex SOQL & SOSL Governor Limits Flows & Process Builder
Advanced Topics
LWC Essentials Security & Sharing Managed Packages Deployment & CI/CD Integration Patterns
Interview Prep
Practice interview questions
Resources
Sales Cloud Class Diagram
Blog AI News
Available Now
Agentforce Pricing Calculator New Debug Log Analyzer SFX Forge New SFX Grove SFX Travel Manager
Salesforce + AI
AI Agent Development Salesforce Agentforce Development Custom RAG Solutions AI + Salesforce Integration Customer Support AI Agents AI Lead Qualification AI Knowledge Base Assistant AI Workflow Automation
Salesforce work
Issue Fix Sprint Automation Sprint LWC & integrations Overflow support for partners Agentforce & AI usage review All services →
About Ask Krrish Contact

Salesforce Packaging: Unlocked, 2GP Managed and Unmanaged Packages Compared

Understand Salesforce packaging, a fundamental concept for distributing and managing your customizations. Learn about Unmanaged, Managed (1GP & 2GP), and Unlocked Packages, and how to create them easily.

Need hands-on help?

Which Salesforce package type should I use?

Use unlocked packages to organise and deploy your own org's metadata in versioned modules. Use second-generation managed packages (2GP) to build and distribute an app to other orgs, for example on AppExchange; Salesforce recommends 2GP over first-generation (1GP) for new managed packages. Use unmanaged packages only to share samples or templates one time, because they can't be upgraded.

  • 2GP packages are created from source with Salesforce CLI and a Dev Hub, not from a packaging org.
  • Managed packages need a namespace and protect their code; unlocked packages can have one but don't have to.
  • Package versions can be promoted and upgraded; unmanaged packages can't.
  • Unlocked packages are the standard way to split a large org into modules.
  • Apps listed on AppExchange must pass the security review.

1. Introduction to Salesforce Packaging

In Salesforce development, once you've built custom functionalities like Apex code, Lightning Web Components, custom objects, or flows, you often need to move these customizations between different Salesforce environments or distribute them to other organizations. This is where Salesforce Packaging comes in.

Salesforce packaging allows you to bundle your metadata into deployable units. These packages can then be installed into other Salesforce organizations, streamlining distribution, deployment, and version management of your applications or components.

Why is Packaging Important?

  • Distribution: Easily share your custom solutions with other Salesforce organizations.
  • Version Control: Manage different versions of your application or components.
  • Deployment: Simplify the process of moving changes across environments or to customers.
  • Intellectual Property Protection: For commercial applications, protect your source code.
  • Modularity: Break down large implementations into smaller, manageable, and reusable units.

This module covers the different types of Salesforce packages — Unmanaged, Managed (1GP and 2GP), and Unlocked Packages — highlighting their characteristics, use cases, and how to create them.

2. Unmanaged Packages

Unmanaged packages are the simplest type and are primarily used for distributing open-source projects, templates, or small self-contained applications. Think of them as a "copy-paste" mechanism for Salesforce metadata.

Key Characteristics

  • Editable: Unmanaged components are editable subject to normal metadata and org restrictions.
  • No Upgrade Path: No built-in mechanism for the original developer to push updates. Recipients must manually re-deploy changes.
  • No IP Protection: Source code of Apex classes, Visualforce pages, etc. is visible and accessible after installation.
  • No Namespace: Components have no unique namespace prefix — higher risk of naming conflicts in the installing org.
  • Deletion: A successful uninstall removes the package components and associated data. Dependencies can block the uninstall.

Use Cases

  • Sharing sample code or templates with other developers.
  • Distributing open-source projects or utilities.
  • Providing a starting point for a customer's implementation that they will heavily customize.
  • Migrating components between non-related developer orgs.

How to Create — Salesforce UI

  1. Log in to your Developer Edition or Sandbox org where your customizations reside.
  2. Go to Setup.
  3. In the Quick Find box, type Package Manager and select Package Manager.
  4. Click New under "Unmanaged Packages".
  5. Provide a Package Name (e.g., "MyUtilityComponents") and optionally a description. Click Save.
  6. On the Package Detail page, click Add Components.
  7. Select the Component Type and the specific components to include. Click Add To Package. Repeat for all components.
  8. Once all components are added, click Upload. Salesforce provides an installation URL to share.

SFDX CLI Context

The SFDX CLI does not have a direct command to create an unmanaged package container. The typical workflow involves developing in a scratch org or sandbox, then using the Salesforce UI Package Manager in that org to create the package.

Bash — SFDX Unmanaged Package Workflow
# Develop your customizations in a scratch org or sandbox.
# With source tracking enabled, retrieve tracked changes to your local project:
sf project retrieve start -o myDevOrg

# Then use the Salesforce UI (Package Manager) in that same org
# to create the unmanaged package, selecting the components
# now present in the org from your SFDX project.

3. Managed Packages (1st Generation & 2nd Generation)

Managed packages are the cornerstone for Salesforce ISVs (Independent Software Vendors) to distribute and sell applications on the AppExchange. They offer intellectual property protection, upgrade capabilities, and a unique namespace.

Key Characteristics (Common to 1GP and 2GP)

  • Protected Components: Managed Apex source is hidden, but Visualforce page content is visible. Subscribers can edit certain managed-component properties, depending on the metadata type.
  • Upgrade Path: Package developers can push upgrades to installed managed packages — customers receive new features and bug fixes.
  • Unique Namespace: All components have a unique namespace prefix (e.g., mycompany__MyComponent__c), preventing naming conflicts.
  • AppExchange Distribution: Managed packages support upgradeable commercial distribution; AppExchange also offers unmanaged solutions.
  • Version Control: Strong versioning capabilities for clear release management.

How do you publish and maintain an AppExchange solution?

Register as a Salesforce partner and prepare the solution for security review before publishing its listing. For a managed package listing, submit the required scans and review materials, resolve findings, and pass the review before distribution.

Prepare listing details, installation instructions, and a plan for subscriber support and licensing. Maintain the solution after publication and respond to Salesforce requests for a security re-review. Review requirements and partner agreements can change, so consult the security review guidance and re-review guidance when planning a release.

a. 1st Generation Managed Packages (1GP)

The traditional approach to managed packaging uses a Developer Edition org (the "packaging org") to create package versions. Teams can develop and test source in scratch orgs, then deploy the components to the packaging org.

  • Limitations: An org-centric release process can be harder to manage for large, modular applications and requires coordinating the packaging org with source control and dependencies.

Creation (High-Level — via Salesforce UI in a Packaging Org):

  1. Request a special Developer Edition org for packaging.
  2. Develop and test the application in scratch orgs, then deploy its metadata to the packaging org for version creation.
  3. In Setup, go to Package Manager.
  4. Register a unique namespace prefix in Namespace Settings if the packaging org does not already have one.
  5. Click New to create a package.
  6. Provide a Package Name and fill in other details. Click Save.
  7. Add all your developed components to this package.
  8. Click Upload to create a new version.

b. 2nd Generation Managed Packages (2GP)

The modern, source-driven approach built on Salesforce DX. Metadata is stored in a Git repository, packages are built from source, and development happens in scratch orgs. This is the recommended approach for new managed packages.

  • Modularity: Supports multiple smaller packages with clear dependencies.
  • Source-Driven: All package definition and development managed in version control (Git).
  • CI/CD Friendly: Integrates seamlessly with automated build, test, and deployment pipelines.
  • Better DX: Uses scratch orgs for isolated, disposable development environments.

Creation (SFDX CLI — High-Level Steps):

  1. Set up Dev Hub and the namespace: Enable Dev Hub and second-generation packaging in your Dev Hub org. Register a namespace in a separate org and link it to the Dev Hub.
  2. Configure sfdx-project.json:
JSON — sfdx-project.json (2GP Managed)
{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true,
      "package": "MyAwesomeApp",
      "versionName": "ver 1.0",
      "versionNumber": "1.0.0.NEXT",
      "ancestorId": null,
      "definitionFile": "config/project-scratch-def.json"
    }
  ],
  "namespace": "mycompany",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "58.0"
}
Bash — Create Package in Dev Hub
sf package create \
  --name "MyAwesomeApp" \
  --path "force-app" \
  --package-type Managed \
  --json \
  --target-dev-hub YourDevHubAlias
# Returns a Package ID (0Ho...). Check the generated packageAliases entry in sfdx-project.json.
Bash — Create Package Version
sf package version create \
  --package "MyAwesomeApp" \
  --installation-key-bypass \
  --code-coverage \
  --wait 10 \
  --json \
  --target-dev-hub YourDevHubAlias
# On success, use the Package Version ID (04t...) to install the package.
# If creation is pending, use the 08c request ID to check its status:
# sf package version create report --package-create-request-id 08c... --target-dev-hub YourDevHubAlias

Create a validated version with code coverage and meet the applicable coverage requirements before promotion. If version creation finishes after the wait period, check the report for the resulting ID and update the version alias in the project file if needed.

Bash — Promote Package Version (for Release)
sf package version promote \
  --package "04tXXXXXXXXXXXXXXX" \
  --json \
  --target-dev-hub YourDevHubAlias

How do managed package versions support upgrades?

Managed 2GP ancestry determines the released versions from which subscribers can upgrade. Set an appropriate ancestor for each new version, review the ancestry tree when maintaining branches, and test upgrades from the versions that subscribers use.

A new managed 2GP version is a beta until it is promoted. Test beta versions in scratch orgs or sandboxes; an installed beta cannot be upgraded. Before promotion, complete validation and meet the applicable Apex coverage requirements. A released version can be distributed to production subscribers. See Salesforce guidance on package ancestry and promotion.

4. Unlocked Packages

Unlocked packages are a type of 2nd Generation package providing a flexible way to manage and deploy metadata for internal projects. They are source-driven and version-controlled, but their components are editable after installation — a modern alternative to Change Sets and the Ant Migration Tool.

Key Characteristics

  • Source-Driven & Version-Controlled: Built from source in a Git repository, promoting modern development practices.
  • Editable Components: The key differentiator — components are editable after installation. Great for internal teams needing to make adjustments directly in a sandbox.
  • Upgrade Path: Supports upgrades, but changes made in the target org can be overwritten by new package versions.
  • No Namespace (Typically): Unlocked packages typically don't have a unique namespace, which can lead to naming conflicts if not managed carefully.
  • Internal Use: Designed for internal development teams to modularize their own Salesforce customizations — not intended for AppExchange distribution.
  • Deletion: A successful uninstall removes the package components and associated data. Dependencies can prevent uninstallation.

Use Cases

  • Modularizing large enterprise Salesforce implementations into smaller, manageable units.
  • Managing metadata for internal projects with version control and CI/CD.
  • Facilitating agile development and continuous delivery for internal teams.
  • Replacing Change Sets and Ant Migration Tool for complex internal deployments.
  • Distributing common components or base configurations across multiple internal orgs.

How to Create (SFDX CLI)

This example creates a namespace-free package, which can help when migrating existing metadata. Salesforce recommends a namespaced unlocked package for new metadata.

JSON — sfdx-project.json (Unlocked)
{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true,
      "package": "MyInternalApp",
      "versionName": "ver 1.0",
      "versionNumber": "1.0.0.NEXT",
      "ancestorId": null,
      "definitionFile": "config/project-scratch-def.json"
    }
  ],
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "58.0"
}
Bash — Create Unlocked Package
sf package create \
  --name "MyInternalApp" \
  --path "force-app" \
  --package-type Unlocked \
  --no-namespace \
  --json \
  --target-dev-hub YourDevHubAlias
# Returns a Package ID (0Ho...). Check the generated packageAliases entry in sfdx-project.json.
Bash — Create Package Version
sf package version create \
  --package "MyInternalApp" \
  --installation-key-bypass \
  --wait 10 \
  --json \
  --target-dev-hub YourDevHubAlias
# On success, use the Package Version ID (04t...) to install the package.
# If creation is pending, use the 08c request ID to check its status:
# sf package version create report --package-create-request-id 08c... --target-dev-hub YourDevHubAlias
Bash — Install Package in Target Org
sf package install \
  --package "04tXXXXXXXXXXXXXXX" \
  --target-org mySandboxAlias \
  --wait 10

How do you manage dependencies and package removal?

Declare package dependencies in the project configuration and install prerequisites before packages that depend on them. Test the installation order and compatible versions in a representative org. An org-dependent unlocked package can rely on unpackaged metadata already in the installation org; Salesforce validates that metadata at installation. This variant cannot depend on other packages, so test it in a sandbox containing the required metadata.

Before removing components or uninstalling a package, review metadata-specific removal rules and references, back up needed data, and test the change. References can block uninstallation, and a successful uninstall removes package components and associated data. See org-dependent packages and uninstall considerations.

5. Choosing the Right Package Type

The choice of package type depends heavily on your use case, audience, and development methodology.

Unmanaged Packages

  • Use when: Simple code sharing, open-source projects, templates, small one-off deployments where the recipient needs to edit the components, subject to metadata and org restrictions, and no future upgrades are expected.
  • Avoid when: Building commercial applications, requiring IP protection, or needing a clear upgrade path.

Managed Packages (2GP preferred for new)

  • Use when: Building applications for the Salesforce AppExchange, commercial products, solutions requiring IP protection, and a robust upgrade mechanism.
  • Avoid when: Internal organizational customizations where full editability is desired, or for simple deployments not intended for broad distribution.

Unlocked Packages

  • Use when: Internal enterprise development, modularizing large Salesforce orgs, adopting source-driven development and CI/CD, replacing Change Sets, or distributing common internal components.
  • Avoid when: Distributing upgradeable commercial packages on AppExchange or when strict IP protection is required.

For most internal development, Unlocked Packages combined with Salesforce DX and a robust CI/CD pipeline are the recommended modern approach — offering the benefits of version control and automation while retaining flexibility.

6. Conclusion & Key Takeaways

Salesforce packaging is a powerful mechanism for managing and distributing your customizations. Understanding the different package types and their appropriate use cases is crucial for efficient and scalable Salesforce development.

Key Takeaways

  • Unmanaged Packages: Simple sharing, editable subject to metadata and org restrictions, no upgrade path. Best for open-source and templates.
  • Managed Packages: For AppExchange products, IP protection, and controlled upgrades. 2GP is the modern, source-driven approach.
  • Unlocked Packages: For internal enterprise development, modularity, version control, and flexible upgrades. A modern alternative to Change Sets.
  • Salesforce DX & SFDX CLI: Essential tools for modern packaging (2GP and Unlocked), enabling source-driven development and CI/CD.

By leveraging the right packaging strategy, you can streamline your development lifecycle, improve collaboration, and ensure the consistent and reliable deployment of your Salesforce solutions.

Frequently asked questions

What is a managed package in Salesforce?

A managed package is a versioned, upgradeable bundle of metadata with its own namespace, used to distribute an app to other orgs, often through AppExchange. Its Apex code is hidden from subscribers, and publishers can push upgrades without overwriting the subscriber's data.

What is the difference between 1GP and 2GP managed packages?

1GP packages are built and versioned inside a single packaging org. 2GP packages are built from source in version control using Salesforce CLI and a Dev Hub, can share a namespace across several packages and fit modern CI/CD. Salesforce recommends 2GP for new managed packages.

What is the difference between an unlocked and an unmanaged package?

Unlocked packages are versioned and upgradeable, and the metadata stays linked to the package. Unmanaged packages are a one-time copy: once installed, the components belong to the org and can't be upgraded.

Do I need a namespace for a package?

Managed packages need a namespace. Unlocked packages can be created with or without one; most internal teams use no namespace.

What is a Dev Hub?

A Dev Hub is a Salesforce org, usually production or a Partner Business Org, with the Dev Hub feature enabled. It is used to create scratch orgs and to create and manage second-generation and unlocked packages.

Sources: Salesforce DX Developer Guide: Second-generation managed packages

Get Expert Help

SFX Support — Salesforce + AI solutions. Independent: not affiliated with, endorsed by, or a partner of Salesforce, Inc. Salesforce and Agentforce are trademarks of Salesforce, Inc.