Courseiva
Performance →hardMultiple Choice

SF-PD2 Performance Practice Question

A developer is optimizing a Visualforce page that displays a large table of Opportunity records. The page uses a StandardSetController and iterates over the records to display fields. Users report that the page loads slowly, and the developer notices that the page makes a SOQL query for each Opportunity to retrieve the Owner's Name. The developer wants to improve performance by reducing the number of queries. What is the most efficient way to achieve this?

⚠ Common exam trap

The trap here is thinking that caching or formula fields can replace the need for a relationship query, when the simplest and most efficient solution is to fetch related data in the initial query.

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

✓

Use a SOQL query with a relationship query to retrieve the Owner's Name along with the Opportunity records in the StandardSetController.

The performance issue is caused by the page making a separate SOQL query for each Opportunity to get the Owner's Name. By using a relationship query in the StandardSetController, the Owner's Name is retrieved in the same query as the Opportunities. This reduces the total number of queries to one, significantly improving page load time. The other options either do not reduce queries or add unnecessary complexity.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Create a formula field on Opportunity that references the Owner's Name and display that field in the Visualforce page.

    Why it's wrong here

    Formula fields are calculated at query time and do not require additional queries, but they cannot reference cross-object fields like Owner.Name directly in all cases. While it is possible to create a formula field that references Owner.Name, it would still be evaluated during the query, and the formula field would be included in the SOQL query. However, this does not eliminate the need for the relationship query; it just moves the logic to a formula. It is not the most efficient way because formula fields can impact performance and are not necessary when a relationship query can directly fetch the Owner's Name.

  • ✗

    Enable lazy loading on the Visualforce page so that Owner's Name is loaded only when the user scrolls to that row.

    Why it's wrong here

    Lazy loading is not a native Visualforce feature and would require custom JavaScript and Apex controllers. It does not reduce the number of queries; it only defers them. This adds complexity and may not solve the performance issue, especially if the user scrolls through many records. It is not the most efficient approach.

  • ✗

    Use a Platform Cache to store the Owner's Name for each Opportunity and retrieve it from the cache instead of querying.

    Why it's wrong here

    Platform Cache can improve performance for frequently accessed data, but it requires populating the cache first, which still involves queries. For a one-time page load, using a relationship query is simpler and more efficient. Caching adds overhead and complexity, and may not be beneficial if the data changes frequently or if the cache is not warmed.

  • ✓

    Use a SOQL query with a relationship query to retrieve the Owner's Name along with the Opportunity records in the StandardSetController.

    Why this is correct

    Using a relationship query (e.g., SELECT Id, Name, Owner.Name FROM Opportunity) in the StandardSetController's query retrieves the Owner's Name in the same query as the Opportunities. This eliminates the need for additional queries for each Opportunity, reducing the total number of queries and improving page load time. It is the most efficient way to fetch related data.

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 →

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.