Courseiva
User Interface →mediumMultiple Choice

SF-PD2 User Interface Practice Question

A developer is building a Lightning Web Component for a Lightning Experience app. The component contains a form with an <input> for a search term and a list of results. When the user types into the input, the component must call an Apex method that returns matching records. The developer observes that the Apex method is being invoked on every keystroke, causing excessive server calls. Which technique should the developer use to limit the number of Apex calls while still updating the results as the user types?

⚠ Common exam trap

The trap here is assuming that @wire automatically debounces or that cacheable=true reduces call frequency when parameters change.

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

✓

Implement a debounce function using setTimeout and clearTimeout to delay the Apex call until the user pauses typing.

Debouncing is the correct technique to limit Apex calls triggered by rapid user input. By delaying the call until the user pauses typing, the component reduces server load while still providing timely results. Other options either do not control timing or do not effectively reduce the number of calls in this scenario.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Set the Apex method to cacheable=true and call it imperatively from the component's JavaScript.

    Why it's wrong here

    Caching with cacheable=true improves performance only when the same parameters are used repeatedly. In this scenario, the search term changes with each keystroke, so the cache will miss and the method will still be called each time. It does not reduce the frequency of calls.

  • ✓

    Implement a debounce function using setTimeout and clearTimeout to delay the Apex call until the user pauses typing.

    Why this is correct

    Debouncing delays the Apex call until a period of inactivity has passed after the last keystroke. This reduces the number of calls to one per pause, which is the standard technique for limiting server calls in LWC. It is the correct approach because it controls the timing of imperative Apex calls.

  • ✗

    Use the lightning-input component with the onchange event and call the Apex method only when the input value length exceeds three characters.

    Why it's wrong here

    Checking length does not prevent calls on every keystroke after the third character. It only skips very short terms, but the user will still trigger many calls while typing a longer word. This does not effectively limit the number of Apex calls to a manageable rate.

  • ✗

    Use the @wire decorator with the Apex method and pass the search term as a reactive parameter.

    Why it's wrong here

    The @wire decorator does not provide debouncing or throttling. It will call the Apex method whenever the reactive parameter changes, which occurs on every keystroke. This does not solve the excessive server calls problem and may even worsen it by automatically invoking the method without control over timing.

About these practice questions

Courseiva writes every SF-PD2 question from scratch — 226 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.