Lightning Web Components are announced as part of Spring19 pre-release. Welcome in Lightning Web Components Worlds. In this post we will talk about what is Lightning web component (LWC), why lightning web component and how to very first lightning web component.
What is Lightning Web Component :-
Lightning Web Components is a new framework for building Lightning components. For Lightning Web Components development you need to setup SalesforceDX and VsCode as Lightning web component are currently not available in Developer console. If you want to know more about lightning web component please check our webinar recording of "Introduction to Lightning Web Components". In ApexHours Session we covered all below topic :-- Why Lightning Web Component (LWC)
- Part 1 – Vanilla HTML5 Web Components
- Benefits of Web Component
- Pillars of Web Component
- Demo of Custom Element and Templating
-
Part 2 – Lightning Web Component
- Hello World
- Demo of Lifecycle methods
- Call Apex Class
- Access Custom Label
- Lightning Data Services
- Communication between Lightning Component and LWC
Let see how to create very First Lightning Web Component.
Step 1) Setup SalesforceDX with VSCode.
- Download and Setup Salesforce CLI.
- Download and Install Salesforce VsCode.
- Install required Extension
Step 2) Create SalesforceDx Project
1) Create Project:In our last post we talk about how to use SalesforceDx with non-scratch org. We will use same approch here. Press "CTRL+SHIFT+P" then select "SFDX:Create Project with Manifest"
Then enter project and select folder.
2) Authorize your org :
Press "CTRL+SHIFT+P" then select "SFDX: Authorize an Org"
Step 3) Finally Create your first Lightning Web Component
- Press CTRL+SHIF+P then Type Web Component and then select "SFDX: Create Lightning Web Component"
- Then Select Folder where you want to save your LWC component
- Then provide Component Name.
- Verify your components under lwc folder.
Step 4) Lets do some coding
Lets create one very simple lightning component with HelloWorld :)
HelloWorld.html
<template>
<lightning-card title="HelloWorld" icon-name="custom:custom14">
<div class="slds-m-around_medium">
<p>Hello, {greeting}!</p>
<lightning-input label="Name" value={greeting} onchange={changeHandler}></lightning-input>
</div>
</lightning-card>
</template>
<lightning-card title="HelloWorld" icon-name="custom:custom14">
<div class="slds-m-around_medium">
<p>Hello, {greeting}!</p>
<lightning-input label="Name" value={greeting} onchange={changeHandler}></lightning-input>
</div>
</lightning-card>
</template>
HelloWorld.js
import { LightningElement, track } from 'lwc';
export default class HelloWorld extends LightningElement {
@track greeting = 'World';
changeHandler(event) {
this.greeting = event.target.value;
}
}
export default class HelloWorld extends LightningElement {
@track greeting = 'World';
changeHandler(event) {
this.greeting = event.target.value;
}
}
HelloWorld.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="helloWorld">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="helloWorld">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Step 5) Deploy your component in Org.
Once you are done with coding. Select LWC folder and right click on same then from menu select "SFDX: Deploy Source to Org".Step 6) Verify your Changes with App Builder.
Open your app builder and add your Custom Component on page/App
Here is your first Lightning Web Component.
NOTE:- Make sure Domain is enable in your Org. Else Custom Component will not visible in app builder.
I just record all this step in on Recording and posted same YouTube. Here is recording.
We also did one session on LWC best Practice with "René Winkelmeyer". Please check this recording to learn more about Lwc.
Please check below post on Lightning Web Components:-
- Lightning Web Components ( LWC ) in Salesforce with Non-Scratch Org
- Invoke Apex Controller from Lightning Web Component | Lightning Web Component inside Another LWC
- Design attributes in Lightning Web Components | CSS and SVG Files | Lightning Web Components | targetConfigs
- How to get current user id in lightning web component | Access logged in user ID in LWC
- Toast Notification in Lightning Web Components | ShowToastEvent | (LWC)
- Lightning Web Components Best practices
- Events in Lightning web components (LWC) | Communicate with Events
- Lightning datatable In Lightning Web Components | lightning datatable inline edit
- Lightning Message Service (LMS) | MessageChannel
Further Reading:
Check our YouTube Channel for more recording in Lightning Web Components.
Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com
Check our YouTube Channel for more recording in Lightning Web Components.
Thanks,
Amit Chaudhary
amit.salesforce21@gmail.com
HI amith,
ReplyDeleteI created one sample lightning web component and deploy to my org this component is showing in below screenshot
but it's not showing in lightning app builder i already emaple domian
https://rassas-dev-ed.lightning.force.com/lightning/r/Contact/003B000000EI9KOIA1/view
Can your please help me on this.
You need to update your xml file
ReplyDeletelightning__AppPage
lightning__RecordPage
lightning__HomePage
Hi Amith,
ReplyDeleteThis helloworld custom component is not visible in lightning app builder. I have also enabled My domain in my org.
Can your please help me on this.
Please this recording https://www.youtube.com/watch?v=V_riFQU5iNA
DeleteDid you added isExposed = true in your meta.xml file ? And add target tag with lightning__AppPage
ReplyDeleteThanks, this helped
DeleteHey Amit,I need your urgent help,in which metadata LWC comes under?So for Aura we have AuraDefinitionBundle,but am not sure about LWC,not able to see LWC Component in AuraDefinitionBundle.
ReplyDeleteIt will come under LightningComponentBundle
DeleteHey Amit I got to know that Metadata,I have another doubt,when am trying to open VScode through Mavensmate not able to see vscode folder in Vscode Application.
ReplyDeleteI will recommend you to use VsCode with SFDX https://www.youtube.com/watch?v=7qR0c8h5cCU&t=12s
DeleteThis comment has been removed by the author.
ReplyDeleteHi Amit,
ReplyDeleteHow to lightning web component in the custom button or action.
Hi Amit,
ReplyDeleteI am able to create LWC in using scratch org and non-scrath org both after 'Dev Hub' is now available in Dev Edition sandbox.
Still i am in confusion here.
1. I am working in my 'Dev Edition sandbox' and i am creating my apex classes from there and aura components as well. And that is not using DX. i am using VS Code. [The project is open in VS Code]
2. Now i want to build Web component in same project. Now how to do that. Because, folder structure of Dx project is differ. And project i am currently working is differ.
hello sir !
ReplyDeletegood evening !!
How to create looup in lightning web components?? please helpo me put
Hi Amit,
ReplyDeleteCan you please help me Lightning Web Component for Close Case button.
Thanks,
Hello amit
ReplyDeletei am huge fan of your blog, i need a small help on lwc
My requirement is that i am working on a real estate project,
i have two objects, (opportunity) and custom object (Appartment__c), whenever a block a flat in a opportunity object, the same blocked flat should show in appartment objects, i have created UI for the button components, and i have put that lightning component in both objects, how can i achive this?
if you want i share me UI code
Please reply me back when you are free at manjuzmail053@gmail.com
DeleteHi Amit,
ReplyDeleteI'm not able to deploy the component to the Org. In my VSC I'm not getting the option to perform this. Rest all I did and it works fine. Is there anything that I need to install in the VSC in order to push the changes to source org?
Hi Amit,
ReplyDeleteI'm not able to deploy the component to the Org. In my VSC I'm not getting the option to perform this. Rest all I did and it works fine. Is there anything that I need to install in the VSC in order to push the changes to source org?
I hope you installed the Salesforce CLI
DeleteHey! great post you shared. It was amazing to read whole new update also want to add more about custom lables here for you. It is good to know about new things.
ReplyDeleteHi Amit,
ReplyDeleteI am not able to find css option of any LWC in vscode tool.
Could you please help me on this ?
Please check below post/ Recording
Deletehttp://amitsalesforce.blogspot.com/2019/01/design-attributes-in-lightning-web-components-css-svg.html
Share some artile related to Navigation page to page and different types
ReplyDeleteWe will post soon
DeleteThanks Amit, for this awesome document. As new to salesforce, I was struggling alot to deploy my first app of org.
ReplyDeleteGlad this helped you
DeleteHi Amit, i am not getting 'SFDX:Deploy Source to org' option. Please help.
ReplyDeleteYou need to authenticate first
DeleteIF any of you have Lightning Web Component expereience and interested to work with me please let me know.
ReplyDeleteIs it possible create chatter functionality in the LWC or access chatter in LWC?
ReplyDeleteThanks a lot Amits, very good tutorial.
ReplyDeleteGlad it helped you. Check this post for recording http://www.apexhours.com/lightning-web-components/
DeleteHi Amit,
ReplyDeleteCan we create Bulk Object Creation using CSV file in Sales Force ?
Hi Amit,
ReplyDeleteCan we create Dynamic Form Builder in LWC ?
Hi Amith,
ReplyDeleteI have below doubts could you please clarify them.
• In lightning Web Component, can we create custom object using visual studio code.
• Suppose I have created one component for employee data table and displaying the records and when I click on name-hyperlink record does it navigate to Record page?
Hi Amit,
ReplyDeleteIts showing me error:
"Lightning_AppPage is not a valid target" while pushing the changes to scratch org.
I think you need to add double Underscore between Lightning and AppPage. so it will be like Lightning__AppPage
DeleteThis comment has been removed by the author.
ReplyDeleteHello,
ReplyDeleteI have created a LWC and it is also visible in app builder but when i add that component to home page it is not getting saved. And i have also done all configurations also like,
true
lightning__AppPage
lightning__RecordPage
lightning__HomePage
Link exchange is nothing else but it is only placing the other person's web site link on your page at proper place and other person will also do similar in favor of you.
ReplyDeleteI every time emailed this web site post page to all my associates, since if like to read it afterward my contacts will too.
ReplyDeleteHello sir
ReplyDeleteCSS class selector 'slds-m-around_medium' not found.
Details Error
{
"resource": "/f:/LWC/HelloWorld/force-app/main/default/lwc/helloWorld/helloWorld.html",
"owner": "_generated_diagnostic_collection_name_#0",
"severity": 4,
"message": "CSS class selector 'slds-m-around_medium' not found.",
"startLineNumber": 3,
"startColumn": 19,
"endLineNumber": 3,
"endColumn": 39
}
Please Reply kanaramyadavofficial@gmail.com