Skip to content

Latest commit

 

History

History
80 lines (60 loc) · 3.34 KB

salesforce-apps-with-lightning-web-components.md

File metadata and controls

80 lines (60 loc) · 3.34 KB

Salesforce Apps with Lightning Web Components

How to Create Salesforce Apps with Lightning Web Components

Creating Salesforce apps with Lightning Web Components (LWC) involves several steps, from setting up your development environment to deploying your app. Here's a concise guide to help you get started.

Step 1: Set Up Your Development Environment

  1. Install Salesforce CLI:
    • Download and install the Salesforce CLI from the Salesforce website.
    • Verify the installation by running sfdx --version in your terminal.
  2. Set Up Visual Studio Code (VS Code):
    • Install VS Code, a popular code editor.
    • Add the Salesforce Extension Pack from the VS Code marketplace to enhance your development experience.
  3. Create a Salesforce DX Project:
    • Open a terminal in VS Code and run sfdx force:project:create -n myLWCPProject to create a new project.

Step 2: Authorize a Developer Hub

  1. Authorize Your Dev Hub:
    • Run sfdx force:auth:web:login -d -a DevHub to authorize your Developer Hub. This step allows you to create and manage scratch orgs.

Step 3: Create and Configure a Scratch Org

  1. Create a Scratch Org:
    • Run sfdx force:org:create -s -f config/project-scratch-def.json -a myScratchOrg to create a scratch org for development.
    • Open the scratch org with sfdx force:org:open.

Step 4: Create a Lightning Web Component

  1. Generate the Component:
    • In VS Code, open the command palette (Ctrl+Shift+P) and run SFDX: Create Lightning Web Component.
    • Provide a name for your component, and specify the target directory (typically force-app/main/default/lwc).
  2. Component Files:
    • Your new component will have three main files:
      • .html: For the component's HTML template.
      • .js: For JavaScript logic.
      • .css: For styles (optional).

Step 5: Develop Your Component

  1. HTML File:
    • Define the structure of your component in the HTML file. Use standard HTML and LWC-specific directives.

      <template>
          <h1>Hello, {name}!</h1>
      </template>
  2. JavaScript File:
    • Add interactivity and logic in the JavaScript file. Use ES6 modules and Salesforce’s LWC APIs.

      import { LightningElement, track } from 'lwc';
      
      export default class MyComponent extends LightningElement {
          @track name = 'World';
      }
  3. CSS File:
    • Style your component using standard CSS in the optional CSS file.

Step 6: Deploy and Test Your Component

  1. Deploy to Scratch Org:
    • Run sfdx force:source:push to deploy your component to the scratch org.
  2. Add Component to Lightning App Builder:
    • In scratch.org, navigate to the Lightning App Builder.
    • Create a new app or edit an existing one and drag your component onto the page.
  3. Test the component.
    • Save and activate the page. Preview the page to see your component in action.

Step 7: Deploy to Production

  1. Authorize Production Org:
    • Run sfdx force:auth:web:login -a Production to authorize your production org.
  2. Deploy to Production:
    • Run sfdx force:source:deploy -u Production to deploy your components to the production org.

Refer to learn more about Salesforce Apps with Lightning Web Components