- Lightning web components are custom HTML elements built using HTML and modern JavaScript.
- Lightning Web Components uses core Web Components standards.
A component that renders UI has 2 parts.
- An HTML template file.
- A JavaScript class file. which is an ES module
- Lightning Web Components templating system uses the virtual DOM to render components smartly and efficiently.
- Use simple syntax to declaratively bind a component’s template to data in the component’s JavaScript class.
- A template is valid HTML with a
<template>
root tag - You write templates using standard HTML and a few directives that are unique to Lightning Web Components.
- Directives are special HTML attributes, like
if:true
andfor:each
, that give you more power to manipulate the DOM in markup.
- Define a
static
method in the Apex class and annotate it with@AuraEnabled(cacheable=true)
public with sharing class ExampleController {
@AuraEnabled(cacheable=true)
public static void exampleMethod(string recordId) {
}
}
2.Import the static method defined in Apex Class and use it.
import { LightningElement, api } from 'lwc';
import exampleMethod from '@salesforce/apex/ExampleController.exampleMethod'; // Importing Apex Method
export default class ExampleComponent extends LightningElement {
@api recordId;
// Calling Apex Method and passing the param
connectedCallback() {
exampleMethod({recordId: this.recordId})
.then(result => {})
.error(error => {})
}
}
- Lightning Web Components Dev Guide
- LWC | Dev Guide
- Trailhead LWC Sample Apps
- JavaScript modules
- Extend Salesforce with Clicks, Not Code
- SFDCFacts Academy | Lightning Web Component Crash Course | Learn LWC in 100 Minutes with Live Project
- Coding Addict | Javascript Fundamentals
- SFDCFacts Academy | Modern JS Crash Course | The Ultimate Hands-On JavaScript Tutorial 2021 | Learn JS in 3 hour
- Exploring ES6 | Book