1. What is a Lightning Web Component (LWC)?
Lightning Web Component is a Salesforce programming model that leverages modern web standards to develop components for the Salesforce Lightning Platform.
2. What are the key features of Lightning Web Components?
Key features include reusability, encapsulation, performance optimization, and compatibility with modern web standards.
3. How do you pass data from a parent component to a child component in LWC?
You can pass data from a parent to a child component using properties, which are annotated with the
@api decorator in the child component.
4. How can you handle events in LWC?
You can handle events using the
@wire decorator, which binds a component’s property to a value from an Apex method.
5. What is the purpose of the
@wire decorator in LWC?
@wire decorator is used to wire a component’s property to a data source, such as an Apex method or a field on a record.
6. What is the role of the Lightning Data Service (LDS) in LWC?
Lightning Data Service provides a standard way to access and manipulate Salesforce data in Lightning Components, including LWC.
7. How do you make an HTTP callout from a Lightning Web Component?
You can use the
fetch API to make HTTP callouts in LWC. Import the
fetch method and use it to send requests to external services.
8. What is the use of the
@track decorator in LWC?
@track decorator is used to track changes to properties so that the component can rerender when those properties change.
9. How do you handle errors in Lightning Web Components?
You can use the
catch block to catch errors and handle them gracefully. Additionally, you can display error messages to users.
10. What is the difference between
lightning-layout components in LWC?
lightning-card provides a styled container for content, while
lightning-layout is used for creating layouts with multiple regions.
11. Explain the concept of shadow DOM in LWC.
Shadow DOM is a web standard that encapsulates a component’s styles and structure, preventing CSS conflicts with other components on the page.
12. What is the role of the
wire service in LWC?
wire service is a module that provides reactive data binding, allowing you to get and update data from a data source without needing to write boilerplate code.
13. How do you handle user interactions in LWC?
14. What is the purpose of the
api property in LWC?
api property allows you to expose properties and methods in a Lightning Web Component that can be used by parent components or by external code.
15. What is the difference between imperative and reactive Apex methods in LWC?
Imperative methods use
@wire to fetch data when needed, while reactive methods use the
@wire service to automatically update data when it changes.
16. How can you make a Lightning Web Component available for use in the Salesforce App Builder? You need to define a custom component in the
meta.xml file of your LWC and set the
isExposed attribute to
17. What is the purpose of the
lightning-record-edit-form component in LWC?
lightning-record-edit-form is used to create, view, or edit a record’s fields using the Salesforce Lightning Data Service.
18. How can you communicate between sibling components in LWC?
You can use custom events and properties defined in a common parent component to facilitate communication between sibling components.
19. What is the role of the
lightning/navigation module in LWC?
lightning/navigation module allows you to navigate users to different pages within Salesforce, such as records, lists, or custom pages.
20. How do you unit test a Lightning Web Component?
You can write unit tests for LWC using Jest framework, which is supported by Salesforce. Test components, properties, and methods using Jest functions.