PD1 User Interface 2 — Questions and Answers
Question 1: Which Lightning Web Component lifecycle hook is called after every render of the component?
- connectedCallback()
- renderedCallback() (Correct answer)
- disconnectedCallback()
- constructor()
Correct answer: renderedCallback()
renderedCallback() fires after each render cycle, making it suitable for DOM manipulation after rendering.
Question 2: In a Lightning Web Component, which decorator is used to expose a property so that parent components can set its value?
- @track
- @wire
- @api (Correct answer)
- @observable
Correct answer: @api
@api makes a property or method publicly accessible to parent components and in markup.
Question 3: What is the correct way to call an Apex method imperatively in a Lightning Web Component?
- Use @wire with the Apex method directly
- Import the Apex method and call it as a JavaScript function (Correct answer)
- Use $A.enqueueAction() to invoke the method
- Declare the method in the component's XML configuration file
Correct answer: Import the Apex method and call it as a JavaScript function
Imperative Apex calls require importing the method from the Apex namespace and calling it as a standard JS function returning a Promise.
Question 4: Which attribute in a Lightning Web Component's JS-meta.xml file controls where the component can be placed by admins in Lightning App Builder?
- isExposed
- targets (Correct answer)
- targetConfigs
- apiVersion
Correct answer: targets
The <targets> element specifies which Lightning App Builder page types (e.g., recordPage, homePage) can host the component.
Question 5: In Visualforce, which tag renders a standard Salesforce page layout for a specific object record?
- <apex:detail> (Correct answer)
- <apex:pageBlock>
- <apex:relatedList>
- <apex:form>
Correct answer: <apex:detail>
<apex:detail> renders the standard detail view page layout for the record associated with the page's controller.
Question 6: A developer needs to display a list of records in an LWC and refresh it whenever a new record is created via a child component. What is the best mechanism?
- Use window.postMessage to notify the parent
- Dispatch a custom event from the child and handle it in the parent to re-call the wire adapter (Correct answer)
- Use @track on the list variable so it auto-refreshes
- Reload the entire page using window.location.reload()
Correct answer: Dispatch a custom event from the child and handle it in the parent to re-call the wire adapter
The child fires a custom event; the parent listens, then calls refreshApex() or re-invokes the wire adapter to reload data.
Question 7: Which of the following is true about Lightning Aura Components and Lightning Web Components running on the same page?
- LWC and Aura components cannot exist on the same Lightning page
- Aura components can contain LWC components but not vice versa
- LWC components can contain Aura components using the <c-aura> tag
- Both can coexist; Aura can wrap LWC and LWC can wrap Aura using interop adapters (Correct answer)
Correct answer: Both can coexist; Aura can wrap LWC and LWC can wrap Aura using interop adapters
Salesforce supports interoperability: Aura components can include LWC components, and LWC can include Aura components via an interop layer.
Which Lightning Web Component lifecycle hook is called after every render of the component?