SF-PD2 User Interface Practice Question
A developer is building a Lightning Web Component that must expose a public method so a parent component can programmatically trigger a refresh of the child's data. The child component's method is decorated with @api and named refreshData. The parent component holds a template reference to the child element. Which code in the parent correctly invokes the child method?
⚠ Common exam trap
The trap here is assuming Lightning Web Components use the Aura cmp.get('c.method') invocation style, when @api methods are simply called as normal JavaScript functions on the element.
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
✓
this.template.querySelector('c-child').refreshData();
Public methods on a Lightning Web Component are declared with @api and become callable JavaScript methods on the element instance. A parent obtains the child element through a template query and invokes the method directly. Custom events, aura-style call() helpers, and bare method references do not perform an imperative parent-to-child invocation.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
this.dispatchEvent(new CustomEvent('refreshData'));
Why it's wrong here
Dispatching a CustomEvent from the parent sends information upward or across the DOM; it does not invoke a method on a child element. The child would need a listener to respond, which defeats the purpose of calling a public method. This pattern is for child-to-parent communication, not parent-to-child method invocation.
- ✗
this.template.querySelector('c-child').call('refreshData');
Why it's wrong here
There is no call() method on a Lightning Web Component element. The aura framework used cmp.get('c.refreshData') style invocation, but Lightning Web Components expose @api methods as plain JavaScript methods on the element. Attempting to call a nonexistent call() function throws a TypeError at runtime in this scenario.
- ✓
this.template.querySelector('c-child').refreshData();
Why this is correct
A template reference obtained with querySelector returns the child custom element, and public methods decorated with @api are exposed directly on that element instance. Calling refreshData() on it invokes the child's public method. This is the documented pattern for parent-to-child imperative communication in Lightning Web Components when no reactive property change is involved.
- ✗
this.template.querySelector('c-child').refreshData;
Why it's wrong here
Referencing the method without parentheses retrieves the function object but never executes it. The child's refresh logic would not run, and the parent would silently do nothing. Parent-to-child imperative calls require the parentheses to actually invoke the public method exposed via the @api decorator.
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.