Creating a salesforce lightning web component in visual studio code – User friendly Tech help
import { LightningElement, track } from 'lwc';nnexport default class HelloLWC extends LightningElement {n //default valuesn @track typedValue = '';n salutationOptions = [n {'label': 'None', 'value': 'None'},n {'label': 'Mr.', 'value': 'Mr.'},n {'label': 'Ms.', 'value': 'Ms.'},n {'label': 'Mrs.', 'value': 'Mrs.'},n {'label': 'Dr.', 'value': 'Dr.'},n {'label': 'Prof.', 'value': 'Prof.'},n ];nn //method on click of buttonn handleClick(){n const txtInput = this.template.querySelector('.txtInput');//fetch the input valuen this.typedValue = txtInput.value;//show the valuen }n}
n
Integrating VSCode with Salesforce
n
- n
- n
- n
- Create sfdx project in vscoden
- n
- n
- n
- Launch VSCode > cmd+ shift+P > SFDX:Create Project with Manifest > Enter project Name > Enter
- Skelton sfdx prject is created
n
n
n
n
n
n
- n
- Right click on manifest file > package.xml > SFDX: Reterieve source from Org
- Create lightning web component skeleton n
- n
- n
- n
- cmd+shift+p > SFDX:Create Lightning Web Component > type name of LWC (say helloLWC) > enter (select the default creation path)
n
n
n
n
n
- n
- Add default LWC component from LWC libraryn
- n
- Take code for input box
- Take code for button
- Add the below code into helloLWC.htmln
n n My First salesforce LWC in VSCoden n n
n
Considerations
n
n
n
- n
- Have fun
- Learn LWC
- Share your learning
n
n
n
n
n n n n n nn n n
{typedValue}!n n - Add the below code into helloLWC.jsn
import { LightningElement, track } from 'lwc';nexport default class HelloWorld extends LightningElement {n @track greeting = 'World';n changeHandler(event) {n this.greeting = event.target.value;n }n}
- Add configuration settings, like where to show this component, inside helloLWC.meta.xml file. Read more about meta.xml file in LWCn
nn 45.0n truen n lightning__AppPagen lightning__RecordPagen lightning__HomePagen n
n
n
n
n
n
n
- Deploy code to sandboxn
- n
- Right click lwc > SFDX: Deploy Source to Org
n
n
- Add Component to App in Lightning Experiencen
- n
- Inside your sandbox, App launcher > Sales > gear icon > Edit Page > search
- Drag the given component to canvas
- Save and enjoy the latest added LWC component in sales app
n
n
n
n
n
n
n
n
n
n
n
- Create sfdx project in vscoden
n
n
n
Keep learning and keep sharing
n