Monday, 19 April 2021

Salesforce Unlocked Packages

 Package : A Salesforce package is a container that you fill with metadata,

in order to move from one org to another.


Unlocked Packages : Is a type of Salesforce packages that is especially suited

to for internal business apps not ISV apps (AppExchange).


Workflow for Unlocked Packages 


Second geneation packages are source driven (version control system is the source of truth) and their life cycle

differs from the first generation packages.


   Generate -----> Release ---------> install

   


Note : 


Package version is a snapshot of the metadatas contained in the folder specified during the package creation.



1.We create a package, name it and indicate its source:


sfdx force:package:create -n HelloWrold -d “<my description>” -r force-app -t Unlocked -v DevHubOrg


Our file sfdx-project.json looks more or less like this:


{

“packageDirectories”: [

{

“path”: “force-app”,

“default”: true,

“package”: “HelloWrold”,

“versionName”: “ver 0.1”,

“versionNumber”: “0.1.0.NEXT”

}

],

“namespace”: “”,

“sfdcLoginUrl”: “https://login.salesforce.com”,

“sourceApiVersion”: “43.0”,

“packageAliases”: {

“HelloWrold“: “0Hoxxx”

}

}


2.The next step is to create the version of our package. We can set up a password/key which will protect it from unauthorised use.


sfdx force:package:version:create -p HelloWrold -d force-app -k test1234 —w 10 -v DevHubOrg


sfdx force:package:version:create -p HelloWrold -d force-app -x -w 10 -v DevHubPrivate


If everything is ok, we will get the package version number, and from now on 

we can install it on our sandboxes and scratch orgs. Depending on the model adopted in the project, 

we can create a lot of versions which together comprise the release, 

and finally, we can label the one which is accepted for installation on the production.


3.This operation is carried out with the command promote in the following way:


sfdx force:package:version:promote -p YourPackageName


4.Install the package version into the sandbox/production using the user interface or a command line tool.


sfdx force:package:install -p YourPackageName


Package dependency :


Second generation packages can have dependent packages 

and these dependencies are specified in the sfdx-projet.json 

file.


{

    "path": "force-app",

    "package": "YourPackageName",

    "versionName": "v 1.0",

    "versionDescription": "Summer 2019 Release",

    "versionNumber": "1.0.0.NEXT",

    "dependencies": [

        {

            "package" : "BasePackage@1.0.0"

        }

    ]            

}


Package dependencies are enforced during the package installation,

use this sample script provided by Salesforce to auto-install the package dependencies.

No comments:

Post a Comment