Classic factorial project, done in order to learn the concepts of Salesforce Packaging.
- Visualforce Page
- Apex Controller
- Unit Test
- Custom Tab metadata
- Links to each one of the packages created:
- Package Development Model
- Change Set Development Model
- Org Development Model
- Second-Generation Managed Packages
- Unlocked Packages for Customers
Quick clarification, follow this if you have a project "100% done" including the unit tests with code coverage above 80%. Even though were deployed 3 types of pacakages, all of them are interconnected in a way because of the way I did it, using the same ORGS.
- Install VSCode
- Install Salesforce CLI
- Install Java 11 or 8
- While doing this step, you might run into problems, is suggested to follow the attached note in this trailhead if needed
- Once you got all this setup, your machine will understand the
sfdxcommands and VSCode can perform the shortcuts as well
NOTE: When using CLI use the --help attribute as a wildcard
===========================================================
EX:
sfdx --help
sfdx force --help
sfdx force:source --help- Create a
sfdxproject, could be done through VSCode or CLI- CLI -> Run the command:
sfdx force:project:create -n salesforce-factorial -t standard -x - VSCode -> This app has command line shortcuts by pressing
ctrl+shift+pthen you just look for the options that says "Create Project" and follow along by pressing enter
- CLI -> Run the command:
- At this point you can keep trying to use the VSCode shortcuts or use the Salesforce CLI. I followed the CLI to learn better what's going on in the backstage
- Log to your DevORG
sfdx auth:web:login - Retrive your DevORG information needed for the deployment of the package, thinkgs like Tabs, Objects, LWC, Apex code... for example:
sfdx force:source:retrieve -m ApexClass:MyApexClass
- We first need to create an Artifact (.zip file containing all the source code)
- Create an Artifact with
sfdx force:source:convert -r ./src/folder -d ./deployFolder -n "Package Name" - Previous step will create a folder, so turn that folder into .zip file
- Log to your PackagingORG
sfdx auth:web:login - Deploy the Artifact
sfdx force:mdapi:deploy -f artifact.zip -u PackagingORG - In your PackagingORG go to Setup>Package Manager>New and select the necessary items that belongs to the package funcionality, this includes Tests
- Click Upload, a link will be generate and can be shareable
- In your PackagingORG setup your namespace in Package Manager, once verified your unique namespace, select the package to be managed
- Setup your DevhubORG by login to your destinated DevhubORG and then in the setup>Dev Hub> switch to "Enabled" these options: Enable Dev Hub & Enable Unlocked Packages and Second-Generation Managed Packages
- Previous step allows your DevhubORG to have access to next tab "Namespace Register" where you can add with point and click the previously created namespace, login to your PackagingORG will be needed
- Double check that you have added the namespace key in the sfdx-project.json file
- On your CLI setup the DevhubORG, login first
sfdx auth:web:login - CLI
sfdx config:set defaultdevhubusername=devhubAlias - Go back to your PackagingORG go to Package Manager and deploy now the Managed package by uploading once again and this will generate another link
- Create a scratch org for test only, not completely mandatory for this deployment but is a needed concept for 2GP
sfdx force:org:create --definitionfile config/project-scratch-def.json --durationdays 30 --setalias MyScratchOrg -v DevHub - Create a 2GP package through CLI
sfdx force:package:create -n "Package Name" -t Managed -r src-folder - This will generate a package with the Id that starts with "0Ho", for example "0Ho5e0000004CfeCAE"
- You can have the package created, but is necessary to create also a version from that package, it is important to notice that the version Id will start with "04t", for example "04t5e000000viXKAAY"
- While creating this version, you need to run the Apex Tests by adding the parameter -c (--codecoverage) and -x (--installationkeybypass)
- Create a version from previous package created
sfdx force:package:version:create -a "Version Name" -c -p 0Ho5e0000004CfeCAE -x - Now, to share the package, you need to promote it
sfdx force:package:version:promote -p 04t5e000000viXKAAY
This .md file doesn't cover the how to deploy a 2GP Unlock Package, however here's the documentation link
Now that you’ve created a Salesforce DX project, what’s next? Here are some documentation resources to get you started.
Do you want to deploy a set of changes, or create a self-contained application? Choose a development model.
The sfdx-project.json file contains useful configuration information for your project. See Salesforce DX Project Configuration in the Salesforce DX Developer Guide for details about this file.