Setup your Developer Environment For Lightning Web Component (2024)

As you all know, creating a Lightning Web Component in developer console is not possible. You need to write it locally and then push it to your Org. Doing this will need to setup your developer environment. How…. ?

You need a set of tool like Visual studio code, Salesforce command line interface and an Org. Salesforce DX provides you to choose any equivalent tool to them and use for the same.

Note:-Salesforce DX adds new tools that streamline the entire development life cycle. It improves team development and collaboration, facilitates automated testing and continuous integration, and makes the release cycle more efficient and agile.

But Salesforce DX is so much more than just a new set of tools! It provides an alternative to change set development, and shifts the source of truth from the org to your version control system (VCS). It shifts your development focus from org development to package development.

Lets begin with installing Salesforce Command Line Interface. The Salesforce CLI is a powerful command line interface that simplifies development and build automation when working with your Salesforce org. Use it to:

  • Aggregate all the tools you need to develop with and perform commands against your Salesforce org
  • Synchronize source to and from scratch orgs
  • Create and manage orgs
  • Import and export data
  • Create and execute tests
  • Create and install packages

Download the CLI using the appropriate link below.

Operating SystemLink to Installer
macOShttps://sfdc.co/sfdx_cli_osx
Windows 32-bithttps://sfdc.co/sfdx_cli_win
Windows 64-bithttps://sfdc.co/sfdx_cli_win64
Debian/Ubuntu 64https://sfdc.co/sfdx_cli_linux
Download the archive from one of the URLs in the manifest, extract the archive, then run the ./install script.
Debian/Ubuntu x86https://sfdc.co/sfdx_cli_linux_x86
Download the archive from one of the URLs in the manifest, extract the archive, then run the ./install script.
  • Install the CLI through the installer.
  • Make sure the CLI is properly installed.
  • Check the Salesforce CLI is working properly or not by using sfdx in command prompts.
  • Open the terminal app in macOS or the Command Prompt in Windows, and enter sfdx.
  • You will see this:-

Setup your Developer Environment For Lightning Web Component (1)

  • If You are getting below message even after installing it

Setup your Developer Environment For Lightning Web Component (2)

You need to set the path in Environment Variable by following the below process:-

  • From the desktop, right click the Computer icon.
  • Choose Properties from the context menu.
  • Click the Advanced system settings link.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK. for example:- C:\Program Files\Salesforce CLI\bin.It may get change for you according to path directory.
  • Reopen Command prompt window, and run your sfdx command.

The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window.

TheSalesforce CLI Command ReferenceGuide contains information about the Salesforce CLI commands and their parameters.

First, What’s an IDE?

An IDE, or integrated development environment, typically consists of a code editor, build automation tools, a debugger, and intelligent code completion. Visual Studio Code provides these.

Let’s Install Visual Studio Code

You can install Visual Studio Code on any computer running macOS, Windows, or Linux. The system requirements are fairly small so it should run on just about any machine.

  1. Download and install the latest version ofVisual Studio Codefor your operating system. If you already have Visual Studio Code installed, there’s no need to reinstall it.
  2. Launch Visual Studio Code.

Setup your Developer Environment For Lightning Web Component (3)

Install the Salesforce Extension Pack

Now that we have Salesforce CLI installed, we can supercharge Visual Studio Code by installing the Salesforce Extension Pack. The extension pack installs the essential Salesforce extensions all at once, saving you from selecting each one individually.

The extensions provide deep integrations with Salesforce tooling throughout VS Code. You can invoke Salesforce CLI from a variety of places (VS Code menus, shortcut keys, and right-click context menus).

New functionality shows up as you’re working, including:

  • Language Services for Apex
  • Language Services for Visualforce
  • Language Services for Lightning Components (Aura and Lightning Web Components)
  • Integrations in the activity bar for Apex tests and Replay Debugger.

Steps to follow:-

  1. LaunchVisual Studio Code.
  2. On the left toolbar,clickthe Extensions iconSetup your Developer Environment For Lightning Web Component (4).
  3. EnterSalesforce Extension Packin the search field.

You will see like this:-

Setup your Developer Environment For Lightning Web Component (5)

Clickinto the card that says Salesforce Extension Pack. Then in the newly launched window, click the greenInstallbutton. It may take a while to get installed.

Once you Installed it, You don’t need to reload the Visual studio code, You can start using it.

Setup your Developer Environment For Lightning Web Component (6)

Note:- Salesforce has made Lightning Web Component Extension as a part of Salesforce extension pack. Hence, You do not need to install it separately. Refer below image:-

Setup your Developer Environment For Lightning Web Component (7)

Few more steps to go, To work with Lightning web components, you need version 45 or greater of the Salesforce CLI.

Open your Command panel and type:-

sfdx plugins --core

The command outputs version numbers.

@salesforce/plugin-generator 1.0.1 (core)@salesforce/sfdx-trust 2.0.1 (core)builtins 1.0.0 (core)salesforcedx 45.1.2

NOTE:-If you had a prerelease version of the CLI installed, run this command to update it.

sfdx plugins:install salesforcedx@latest

Update Salesforce CLI and its Plugins :-

Run the below command in your command window:-

  • sfdx update

It will update the CLI to latest version as well as the its plugin. You will see something like this:-

sfdx-cli: Updating CLI from 6.0.0-0743bea5 to 6.0.0-aebbfd66 (alpha)... donesfdx-cli: Updating CLI... already on latest version: 6.0.0-aebbfd66sfdx-cli: Updating plugins... done

Set Up Linting

Linting finds errors in your code while you’re editing, before you compile. Linting is more than spell-checking, it steers you away from anti-patterns and towards good patterns. Salesforce has created linting rules to minimize Lightning Web Components programming mistakes.

There are two ways to install the ESLint rules.

Setup your Developer Environment For Lightning Web Component (8)

Bypass the Proxy if you are working on Company firewall

  1. Set Environment variables as follows:
    • Navigate to My Computer,right click on it and select Properties and then Advance System settings
    • Click on “Environment Variables” button
    • On “System variables” section add following two entries
    • The above steps may varies for different kind of system
  2. VariableValue
    HTTP_PROXYhttp:// < UserId >:< Password > @proxy.company.com:8080
    HTTPS_PROXYhttp:// < UserId >:< Password > @proxy.company.com:8080

Set Up a Development Org

Sign up for a Developer Edition org.

You can develop Lightning web components in scratch orgs and non-scratch orgs. To create scratch orgs, configure an org as a Dev Hub. The Salesforce CLI works a bit differently with scratch orgs than it does with non-scratch orgs. We create a project and go over both workflows inDevelopment Workflows.

What’s a Scratch Org?

Many of the new tools enable you to use a new type of org called a scratch org. A scratch org is a dedicated, configurable, and short-term Salesforce environment. Scratch orgs drive developer productivity and collaboration during the development process, and facilitate automated testing and continuous integration. You can use the CLI or Salesforce Extensions for VS Code to open your scratch org in a browser without logging in. You can spin up a new scratch org when you want to:

  • Start a new project.
  • Start a new feature branch.
  • Test a new feature.
  • Start automated testing.
  • Perform development tasks directly in an org.
  • Start from “scratch” with a fresh new org.

Although scratch orgs are meant to be disposable, the scratch org configuration files contain the real brawn. Through the configuration file, you can configure the scratch org with different Salesforce editions and with just the features and settings you want. And you can share the scratch org configuration file with other team members. That way, you all have the same basic org in which to do your development.

Enable Dev Hub

A Dev Hub provides you and your team with the ability to create and manage scratch orgs. Scratch orgs are temporary Salesforce environments where you do the bulk of your development work in this new source-driven development paradigm.

To get started with scratch orgs, you choose an org to function as your Dev Hub. While you can enable Dev Hub in any paid org, it’s always best to practice somewhere other than production. Instead, go ahead andenable Dev Hubin a Developer Edition org or Trailhead Playground to use with this module.

  1. Launch your Org.
  2. ClickSetup your Developer Environment For Lightning Web Component (9)and selectSetup.
  3. From Setup, enterDev Hubin the Quick Find box and select Dev Hub.
  4. To enable Dev Hub, clickEnable.

Enable My Domain in Your Development Org

To use Lightning web components in any org, set up a My Domain name, which is a subdomain within the salesforce.com domain. For example,>trailheadis a subdomain of the Salesforce domain:>trailhead.salesforce.com.

When My Domain isn’t deployed in your org, user interface controls related to Lightning web components may be hidden or inactive.

Create a Salesforce DX Project

A project consists of several local configuration files, as well as the code you want to deploy. In Salesforce terms we call this code metadata, which is the foundation of the Salesforce Platform.

We’ll use Visual Studio Code to create a project.

  1. OpenVisual Studio Code.
  2. PressCommand + Shift + Pon macOS orCtrl + Shift + Pon Windows or Linux, then typecreate project. SelectSFDX: Create Project, and pressEnter.
  3. Entertrailheadas project name, and pressEnter.
  4. Choose a directory on your local machine where the project will be stored. ClickCreate Project.

Authorize Your Dev Hub

  1. InVisual Studio Code, pressCommand + Shift + Pon macOS orCtrl + Shift + Pon Windows or Linux.
  2. Typesfdx.
  3. SelectSFDX: Authorize a Dev Hub.
  4. Log in using your Dev Hub org credentials.
  5. ClickAllow.Setup your Developer Environment For Lightning Web Component (10)
  6. After you authenticate in the browser, the CLI remembers your Dev Hub credentials. The success message should look like this:Setup your Developer Environment For Lightning Web Component (11)

Create a Scratch Org

  1. In Visual Studio Code, pressCommand + Shift + Pon macOS orCtrl + Shift + Pon Windows or Linux.
  2. Typesfdx.
  3. SelectSFDX: Create a Default Scratch Org….
  4. PressEnterto accept the defaultproject-scratch-def.json.
  5. PressEnterto accept the defaulttrailheadscratch org alias.
  6. PressEnterto accept the default7 daysscratch org duration.
  7. Be patient, creating a scratch org can take a minute. The success message should look like this:Setup your Developer Environment For Lightning Web Component (12)

Create a Lightning Web Component

Creating a Lightning web component is a straightforward process. And Salesforce CLI already created a project structure that helps make getting started even easier.

The folder structure looks like this:

Setup your Developer Environment For Lightning Web Component (13)

The project we created has a special folder,force-app/main/default. This folder, called a package directory, contains all the metadata of your current Salesforce DX project. Because Lightning web components are also metadata, they are stored in a subfolder namedlwc. In the next step, we add a Lightning web component to this folder.

We can use Visual Studio Code for creating a Lightning web component, just as we did to create the Salesforce DX project. Or we can use Salesforce CLI directly.

  1. OpenVisual Studio Code.
  2. PressCommand + Shift + Pon macOS orCtrl + Shift + Pon Windows or Linux, then typefocus terminal.PressEnter.
  3. Entersfdx force:lightning:component:create -n myFirstWebComponent -d force-app/main/default/lwc --type lwc, and confirm withEnter.

This creates the needed files for your first Lightning web component.

Setup your Developer Environment For Lightning Web Component (14)

These are the parameters you used in the command.

  • -n — This defines the name of the Lightning web component folder and its files.
  • -d — This defines the target directory where the Lightning web component should be created. The target directory must be namedlwc
  • –type — This specifies that you want to create a Lightning Web Component.

Its all about setting the Developer Environment for creating Lightning Web Component.

References:-

Related

Setup your Developer Environment For Lightning Web Component (2024)
Top Articles
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 5662

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.