Accelerator Product Availability LWC - Source

(0 reviews)

Configuration

Deploying the Lightning Web Component (LWC) to Salesforce

  1. Install the Salesforce CLI (SFDX) on your local system.
  2. Set up Visual Studio Code by following this trailhead.
  3. Open the project folder in the Visual Studio Code app (note: must be the root folder in VS Code).
  4. Authorize the org to publish the code (search for SFDX in the command palette).
  5. 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
  6. In Salesforce organization, navigate to Custom Code -> Lightning Components -> Lightning Components and make sure the component is available in the list:

    retail-productavailabilitylwc1.png

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

  1. 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
  2. In the command window, make sure that the Dev Hub org is connected by running this command:
    sfdx force:org:list
    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:

    retail-productavailabilitylwc2.png

  3. Open sfdx-project.json in your favorite text editor and make a note of the sourceApiVersion number.
  4. 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"
    }
  5. 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 the sourceApiVersion number.

Creating a package

  1. From a terminal or command prompt, change to the accelarators-productavailability-lwc directory.
  2. 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.
  3. Open sfdx-project.json. In packageDirectories, you can see the package name that you defined with placeholders for the version name and version number. The command also creates a packageAliases 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

  1. 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
  2. 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"
  3. Save the file.
  4. 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
  5. 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'.
  6. In terminal, take the package installation for testing:
  7. Replace https://efficiency-efficiency-4299-dev-ed.lightning.force.com/ with https://login.salesforce.com/ which is https://efficiency-efficiency-4299-dev-ed.lightning.force.com/packagingSetupUI/ipLanding.app?apvId=04t5f000000GsXqAAK.
  8. 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:

    retail-productavailabilitylwc3.png

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

Reviews

TypeCustom
OrganizationMuleSoft
Published by
MuleSoft Solutions
Published onJan 25, 2022
Asset overview

Asset versions for 2.4.x

Asset versions
VersionActions
2.4.0