SF-PD2 User Interface Practice Question
A developer needs a Lightning Web Component placed on a record page to read the 18-character id of the record currently being viewed, without querying the database or calling Apex. Which approach provides this value directly?
⚠ Common exam trap
The trap here is reaching for an Apex or Visualforce mechanism to read the record id, when the record page already injects it into an @api recordId property.
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
✓
Declare a public property with @api recordId and reference it in the component.
The platform injects the current record id into an @api property named recordId when an LWC is placed on a Lightning record page. This is the direct, no-Apex way to obtain the id. User info adapters, navigation state, and Visualforce page parameters do not supply the record id in this context.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Declare a public property with @api recordId and reference it in the component.
Why this is correct
When a Lightning Web Component is placed on a record page, the platform automatically populates the @api recordId property with the id of the record being viewed. No query or Apex is needed. This is the documented, supported way to obtain the current record id in an LWC.
- ✗
Query the record id in Apex using ApexPages.currentPage().getParameters().
Why it's wrong here
ApexPages.currentPage() is available only in Visualforce controller contexts, not in Lightning Web Components running in Lightning Experience. Calling it from an LWC-adjacent Apex method returns null. The scenario also explicitly forbids Apex, so this fails both technically and by requirement.
- ✗
Call the getUserInfo wire adapter and read the currentRecordId field from the result.
Why it's wrong here
The getUserInfo adapter returns information about the logged-in user, such as id, name, and locale, not the record being viewed. There is no currentRecordId field on its result. Using it here would return undefined for the record id, so it cannot satisfy the requirement.
- ✗
Read the value from the page state by calling NavigationMixin.Navigate with a state object.
Why it's wrong here
NavigationMixin.Navigate is used to move to a URL and optionally pass state; it does not read the current record id. Calling it would trigger navigation rather than return data. The record page already provides the id through the recordId property, so this approach is both incorrect and disruptive.
About these practice questions
One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.