Accelerator Product Availability LWC - Source
Configuration
Deploying the Lightning Web Component (LWC) to Salesforce
- Install the Salesforce CLI (SFDX) on your local system.
- Set up Visual Studio Code by following this trailhead.
- Open the project folder in the Visual Studio Code app (note: must be the root folder in VS Code).
- Authorize the org to publish the code (search for SFDX in the command palette).
- Deploy the component source to org. This is best accomplished from the command line by running the following command from the project directory:
sfdx force:source:deploy --sourcepath force-app/main/default/lwc/inventorycheck
- In Salesforce organization, navigate to Custom Code -> Lightning Components -> Lightning Components and make sure the component is available in the list:
Unlocking packages
To get the source code for accelerator-productavailability-lwc
, open a command window and change to the directory where you want to put the source code. Then, run the following command:
git clone https://github.com/mulesoft-labs/accelerator-productavailability-lwc.git
The git clone
command creates the 'accelerator-productavailability-lwc' folder using the Salesforce DX project structure, which contains a DX project file and a scratch org definition file.
Configuring the package
- To create a package, authorize it first to the Dev Hub org (
admin@solutions-devhub-20211104.demo
), and log in to it by running this command:sfdx force:auth:web:login -d -a DevHub
- In the command window, make sure that the Dev Hub org is connected by running this command:
The output of this command lists any org that youâre connected to, including Dev Hub and scratch orgs. The (D) indicates your default Dev Hub org as shown in the following:sfdx force:org:list
- Open
sfdx-project.json
in your favorite text editor and make a note of the sourceApiVersion number. - Make sure to replace the replace the contents of the
sfdx-project.json
file with the following code:{ "packageDirectories": [ { "path": "force-app", "default": true } ], "namespace": "", "sfdcLoginUrl": "https://login.salesforce.com", "sourceApiVersion": "53.0" }
- Ensure that the
sourceApiVersion
number in the code snippet matches the version number you noted from the original file. If it doesn't, then update thesourceApiVersion
number.
Creating a package
- From a terminal or command prompt, change to the
accelarators-productavailability-lwc
directory. - Create an unlocked package without a namespace and supply the alias or username for your Dev Hub org if itâs not already set as the default:
sfdx force: package:create --name "acceleratorproductavailabilitylwc" --description "InventoryCheck" --packagetype Unlocked --path force-app --nonamespace --targetdevhubusername DevHub
- name â is the package name. This name is an alias you can use when running subsequent packaging commands.
- path â is the directory that contains the contents of the package.
- packagetype â indicates which kind of package youâre creating; in this case, it's unlocked.
- Open
sfdx-project.json
. InpackageDirectories
, you can see the package name that you defined with placeholders for the version name and version number. The command also creates apackageAliases
section, which maps the package name (alias) to its corresponding package ID:{ "packageDirectories": [ { "path": "force-app", "default": true, "package": "âacceleratorproductavailabilitylwcâ", "versionName": "ver 0.1", "versionNumber": "0.1.0.NEXT" } ], "namespace": "", "sfdcLoginUrl": "https://login.salesforce.com", "sourceApiVersion": "52.0", "packageAliases": { "âacceleratorproductavailabilitylwcâ": "0Ho5f000000Cb3uCAC", "âacceleratorproductavailabilitylwcâ@1.0.0-1": "04t5f000000GsXqAAK" } }
Creating a scratch org to test your package version
- Create a scratch org in which to install the unlocked package with the alias
MyScratchOrg
. Testing in a scratch org is a convenient way to perform the unit testing phase of the packaging development lifecycle:sfdx force:org:create --definitionfile config/project-scratch-def.json --durationdays 15 --setalias MyScratchOrg -v DevHub
- Open the
sfdx-project.json
file and make the following edits:- "versionName": "ver 0.1"
- "versionNumber": "0.1.0.NEXT" to "versionName": "ver 1.0"
- "versionNumber": "1.0.0.NEXT"
- Save the file.
- In the
accelerator-productavailability-lwc
directory, create the package version, which associates the metadata with the package. The Apex code in the unlocked packages must meet a minimum 75% code coverage requirement (see the next section) before the package can be installed in a production org:sfdx force: package:version:create -p âacceleratorproductavailabilitylwc" -d force-app --wait 30 -v DevHub
- After the package is installed, open the scratch org to view the package. From Setup, enter 'Installed Packages' in the 'Quick Find' box and select 'Installed Packages'.
- In terminal, take the package installation for testing:
- Replace
https://efficiency-efficiency-4299-dev-ed.lightning.force.com/
withhttps://login.salesforce.com/
which ishttps://efficiency-efficiency-4299-dev-ed.lightning.force.com/packagingSetupUI/ipLanding.app?apvId=04t5f000000GsXqAAK
. - Click 'Install for all users' and install the package. After the installation completes, the beta version appears for the package as shown in the following:
Releasing the Package Version
Make sure your Apex tests meet the 75% code coverage requirement:
sfdx force:package :version:create -p âacceleratorproductavailabilitylwcâ -d force-app -x --wait 30 --codecoverage -v DevHub