Unlocked Packages in Salesforce

Packaging allows you to group various Salesforce Components for distribution or deployment. In this post we will learn about Unlocked Package and difference between unmanaged packages, managed packaged and unlocked package.

What is Unlocked Package?

Salesforce offers different types of packages. Unlocked package is good fit for internal business apps and allowed customer to do modular application development. Unlocked package is the right package type for enterprise customers , Unless they plan to distribute an app on AppExchange. They can use unlocked packages to organize there existing metadata, package an app, extend an app that they’ve purchased from AppExchange, or package new metadata.

Unlocked packages help you to add, edit, and remove metadata in your org in a trackable way. You can install unlocked package to multiple orgs, and upgrade your Salesforce apps easier and faster.

Unlocked packages follow a source-driven development model. The source of truth of the metadata contained within the package is your version control system, not what’s in an org. This model brings with it all the advantages of modern source-driven development models.

Modular Application Development Concepts

With Modular Application Development customer can break the one monolithic app to multiple packages defining dependency between them. Unlock packages allow us to do that. Salesforce enterprise customers mostly used the org-based deployment approaches like Changesets and ANT deployment to deploy metadata to their orgs. With Unlocked Packages, there is way to do Modular Application package-based deployment.

What are the benefits of packaging over Change Sets and ANT Migration Tool?

Unlocked Packages offers certain advantages over Change Sets and the ANT Migration Tool. The following are some key benefits of packaging:

  1. Packages promote a source-driven development approach and version control system. With package versions, you have an immutable, versionable artifact that can be used in CI.
  2. With a version-based approach, you can develop and install different package versions in target orgs and adopt a build once, deploy anywhere approach.
  3. You can express dependencies among packages. With this capability, you can embrace a modular approach where each package contains a set of metadata that represents a distinct unit of functionality, with well-defined dependencies among packages.
  4. Packages provide a repeatable, scriptable and trackable way for managing change as you develop functionality using Salesforce DX.

Types of package in Salesforce

First-Generation Packaging

Before Salesforce DX came along, we had two types of packages:

  • Unmanaged packages used for one-time deployment of metadata.
  • Managed packages is used for Salesforce partners that build and list apps on AppExchange

Second-Generation Packaging

With Salesforce DX, Salesforce launched Unlocked Packages and Managed second-generation packages (aka managed 2GPs). With that Salesforce want modular application development customers as they do for partners. Unlocked Packages are designed primarily to address the packaging needs of customers. Unlocked packages offer a super-set of features compared to unmanaged packages.

Difference between unmanaged packages, managed packaged and unlocked packages

Unmanaged PackageManaged PackageUnlocked Package
Not upgradable Upgradable and has namespaceUpgradable and one can namespace them or choose not to
Metadata elements are not IP ProtectedMetadata elements are IP ProtectedMetadata elements are not locked and can be changed by system admins
Can we created in Salesforce UICan be created in salesforce UI and distributed via appexchangeRequires Salesforce CLI to generate them 
Unmanaged package containers automatically pull dependencyComponents are locked and one cannot modify them directly in production or sandboxAllows you to build your applications in a modular way
Allows for creation of extension packages Easier to manage when codebase is modularized

Building Unlocked packages using Salesforce CLI

Unlocked packages cannot be created using salesforce UI and requires knowledge of salesforce CLI and requires source code in DX Source format. Scratch orgs are not required but a DevHub is mandatory. However scratch orgs are recommended since the deployment to them is faster.

Here is useful Salesforce DX command to create unlocked package. If you are new to SalesforceDX please check this recording.

Create Unlocked package

sfdx force:package:create --name <name> --description <description> --packagetype Unlocked --path force-app --nonamespace --targetdevhubusername <Devhubalias>

Create a package version

sfdx force:package:version:create -p <packagename> -d force-app --wait 10 -v <Devhubalias>

Publishing and Installing Unlocked packages

sfdx-project.json defines the Version Name and version number. Installing can be using the Subscriber Package Version Id. Installation can also be done via the Salesforce CLI.

sfdx force:package:install --wait 10 --publishwait 10 --package <packagename>@1.0.0-1 -r -u <alias>

By Default a BETA package is generated . We can promote a package using below

sfdx force:package:version:promote -p <packagename>@1.0.0-1 -v <DevHubalias>

Creating Dependency between packages

sfdx-project.json can be used to define dependency between packages.

Session Recording

Agenda

  1. Introduction To Salesforce Packaging
  2. Differentiate between unmanaged packages , managed packaged and unlocked packages
  3. Modular Application Development Concepts
  4. Building unlocked packages using salesforce cli
  5. Creating Dependency between packages
  6. Publishing and Installing Unlocked packages

When : MAR. 02, 2019, 10:00 AM ( 8:30 PM IST )
Speaker: Mohith Shrivastava

Here is PPT.

Further Learning

Please subscribe our YouTube channel to get notification for video upload. Check our “Session in 2019” page for all upcoming and old sessions of 2019. Sharing is Caring so Share with your friends

Thanks
Salesforce Apex Hours

3,329 total views, 6 views today

Leave a Comment