Today, you have just developed a small module and you want to share it with another developer so that they can install it in their personal organization or at their client's premises.
Or you are responsible for the development department and you want your developers to review the development architecture carried out on Salesforce.
A solution is available to you "Unlocked Package", make a package, hosted on Salesforce servers and installed by command line or via a URL!
I'm going to start from a fairly simple code directory containing only an "account" page layout and a "SIRET" field, many customers in France need this information and if we install it each time with just one command line.
For the creation of the directory and the field, I let you consult this article: SFDX - Create a Scratch Org - Pull - Push
It's quite simple to create a package, you have to go inside your SFDX directory with your terminal / cmd, then run the following commands:
1 / Ask Salesforce to create a package for our directory:
sfdx force: package: create -n YourPackageName -d "your description" -t Unlocked -r force-app
An identifier is generated.
2 / You must create a version of this package
sfdx force: package: version: create -p PreviouslyGeneratedID -f config / project-scratch-def.json --json
It is possible to add a key to secure the package with a code:
3 / Install the package (for the moment only in Sandbox and developer org)
With the command line:
sfdx force: package: version: list --packages IdentifierDuPackageVersion
With the URL:
You have to replace the start of the url with your example:
At this point your package can only be installed sandbox / development organization.
4 / Promote your package for production environments
sfdx force: package: version: promote -pPackageVersionIdentifier
Now that your package is "Released", you caninstall where you want !
Everything you had in your directory (in my case the SIRET__c field) is now available in the destination organization.
You will have, more or less manual actions to be performed, in my case, I have to activate the visibility and the rights on my field for the different profiles. But I could have set up a permission set (permission set) to avoid this configuration. It will be the opportunity to write a new article.
The final word :
Do not hesitate to make many packages either to share your code, or to have a lighter architecture.
It's easier to maintain small projects than a huge project with a lot of configuration / code.