SF-PD2 User Interface Practice Question
A developer is building a reusable Lightning Web Component that exposes public properties and methods to its parent, and needs to fire an event the parent can handle. Which TWO techniques are valid for this parent-child interaction? (Choose two.)
⚠ Common exam trap
The trap here is believing Lightning Message Service is required for parent-child communication, when LMS is intended for communication across unrelated components or different DOM trees.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Annotate a property with @api so the parent can set it declaratively in markup or imperatively via the component instance.
Direct parent-child communication in LWC uses two complementary mechanisms: @api exposes properties and methods so a parent can pass data down or invoke a child method, and CustomEvent lets the child notify the parent upward, with the parent listening through the on<eventname> template attribute. Reaching into the parent from the child, using LMS for a direct parent-child relationship, or relying on global window state each violates the framework's encapsulation and reactivity model.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use Lightning Message Service to publish a message the parent subscribes to, since LMS is required for any parent-child communication.
Why it's wrong here
Lightning Message Service is designed for communication across unrelated components, different DOM trees, or between LWC and Aura or Visualforce, not for direct parent-child interaction. Using it for a parent and its own child adds needless indirection and overhead. Standard @api properties and CustomEvent dispatch already cover parent-child needs, so LMS is not required and is the wrong tool in this scenario.
- ✗
Store shared state on a window-level global variable so both parent and child can read and write it directly.
Why it's wrong here
Polluting the global window object bypasses the component lifecycle, breaks reactivity, and is not supported by the LWC framework, which discourages global state. Changes to a global variable do not trigger re-rendering, and this pattern invites memory leaks and cross-component interference. Salesforce provides @api, CustomEvent, and LMS for these needs, so a window global is an anti-pattern and never the correct answer.
- ✓
Annotate a property with @api so the parent can set it declaratively in markup or imperatively via the component instance.
Why this is correct
@api is the decorator that makes a property or method part of the component's public API. A parent can set an @api property either declaratively as an attribute in the template or imperatively on the element reference in JavaScript. This is the documented mechanism for exposing data and behavior from a child to its parent, so it directly satisfies the reusable-component requirement.
- ✗
Call the parent's method directly by querying the parent component with this.template.querySelector on the root element.
Why it's wrong here
A child cannot traverse upward to its parent using querySelector; the template query only searches the child's own rendered DOM. There is no supported API for a child to reach into the parent's methods. Even if a reference existed, this would create tight coupling and break encapsulation. The correct direction is parent-to-child for method calls and child-to-parent for events, so this option is invalid.
- ✓
Dispatch a CustomEvent from the child and let the parent attach a handler with the on<eventname> attribute in its template.
Why this is correct
Dispatching a CustomEvent with composed and bubbles set appropriately, then listening in the parent's template using the on<eventname> pattern, is the standard LWC parent-child event mechanism. The parent receives the event and can read event.detail. This gives the child a clean, decoupled way to notify its parent, matching the requirement to fire an event the parent can handle.
About these practice questions
This SF-PD2 question is part of Courseiva's 226-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Salesforce exam blueprint
This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.