A. 3 ways to call apex method from LWC, 1. Wire to a property 2. Wire to a function 3. Imperatively.
2. How to get the updated data when I click on refresh button in LWC?
A. refreshApex method(refresh of cache) if it is imperatively then call getRecordNotifyChange().
3. What is the difference between lightning-record-form, lightning:recordEditForm, lightning:recordViewForm?
A.
A. To navigate in Lightning Experience, Lightning Communities, and the Salesforce app, use the navigation service, lightning/navigation.
The lightning/navigation service is supported only in Lightning Experience, Lightning Communities, and the Salesforce app. It isn’t supported in other containers, such as Lightning Components for Visualforce, or Lightning Out. This is true even if you access these containers inside Lightning Experience or the Salesforce app.
We can use navigation services in LWC to Navigate to Pages, Records, and Lists.
Here are the steps to use Navigation Service.
1. We need to import lightning/navigation module.
2. Apply the NavigationMixin function to your component’s base class.
export default class MyCustomElement extends NavigationMixin(LightningElement) {}
3. Create a plain JavaScript PageReference object that defines the page.
4. To dispatch the navigation request, call the navigation service’s [NavigationMixin.Navigate](pageReference, [replace])
navigateNext() {
this[NavigationMixin.Navigate]({
type: 'standard__navItemPage',
attributes: {
apiName: this.tabName,
},
});
}
The NavigationMixin adds two APIs to your component’s class. Since these APIs are methods on the class, they must be invoked with this reference.
[NavigationMixin.Navigate](pageReference, [replace]): A component calls this[NavigationMixin.Navigate] to navigate to another page in the application.
[NavigationMixin.GenerateUrl](pageReference): A component calls this[NavigationMixin.GenerateUrl] to get a promise that resolves to the resulting URL. The component can use the URL in the href attribute of an anchor. It can also use the URL to open a new window using the window.open(url) browser API.
A. Use Lightning message service to communicate across the DOM between Visualforce pages, Aura components, and Lightning web components, including components in a pop-out utility bar.
Use the Lightning message service functions to communicate over a Lightning message channel.
In a component's Javascript file, import any exports that you need from the lightning/messageService module. Import a message channel using the scoped module @salesforce/messageChannel.
We can publish a message and subscribe to the message over the same message channel (Pub - Sub Model).
Methods in Lightning message services:
- createMessageContext()
- publish(messageContext, messageChannel, message)
- releaseMessageContext(messageContext)
- subscribe(messageContext, messageChannel, listener, subscriberOptions)
- unsubscribe(subscription)
A. Using custom dispatch event in LWC we can pass values into Parent Aura Component. The enclosing Aura component can capture the event and handle it.
const lwcEvent= new CustomEvent('eventname', {
detail:{varible1:value, varible2 : value}
});
this.dispatchEvent(lwcEvent);
Handling event from Aura Component:
<c:childLwcComponent oneventName={handleEvent}></c:childLwcComponent>
A. constructor(), connectedCallback(), disconnectedCallback(), renderedCallback() and errorCallback().
these callbacks can be used to run some code at a particular stage of the component life cycle. So the framework provides the above life cycle hooks to do that.
8. What is the difference between wire apex methods and Imperative apex methods?
A. All primitive data types are reactive by default, but the objects and arrays are reactive if only if their references are changed.
For example, the component will not reRender if a single element of an array is changed or the object's property is changed.
To overcome this we need to use the @track annotation with objects and arrays.
10. When do we need to use @api decorator with a function or a property?
A. When we need to expose the property or a function to the parent (container) component then we annotate with @api decorator, In a simple words, to create a public property or a function.
A. We can use the onchange event in HTML page to get the data into the js controller, whenever the value changes handleChange function in the js file executes and get the data using event.target method.
12. How to send data from parent child component to child component in LWC?
A. We can use @api decorator and pass this property value into the child component as a parameter.
you can check the detail explanation was given here : Pass data from one LWC component to another LWC component using @api decorator
13. What are lightning web component bundle?
A. LWC bundle contains an HTML file, a JavaScript file, and a metadata configuration file and these files are created once we create a Lightning web component. We can also create a .css file for styling purpose and We can also create SVG file for the purpose of displaying icon.
A. We can deploy component by using managed packages, Force.com IDE, Force.com Migration Tool or Change Sets.
A. Syntax : $A.get("$Label.namespace.labelName");
A. We have 3 Decorators in Lightning Web Components.
- @api
- @track
- @wire
- For : each
- Iterative
- myComponent folder
- myComponent.html
- myComponent.js
- myComponent.js-meta.xml
- myComponent.css
- myComponent.svg
No comments:
Post a Comment