PD1 Visualforce Pages 2 — Questions and Answers
Question 1: Which Visualforce component is used to display a list of records in a table format with built-in sorting and pagination?
- <apex:dataTable>
- <apex:pageBlockTable> (Correct answer)
- <apex:listView>
- <apex:repeat>
Correct answer: <apex:pageBlockTable>
<apex:pageBlockTable> renders a table inside a pageBlock with automatic Salesforce styling, sorting, and pagination support.
Question 2: What is the purpose of the 'rendered' attribute in Visualforce components?
- It sets the CSS display property to none
- It conditionally includes or excludes the component from the HTML output (Correct answer)
- It controls whether the component is editable
- It determines if the component fires AJAX requests
Correct answer: It conditionally includes or excludes the component from the HTML output
The 'rendered' attribute accepts a Boolean expression; when false, the component is not emitted in the HTML response at all.
Question 3: Which attribute on <apex:page> disables the standard Salesforce page header?
- showHeader='false' (Correct answer)
- header='false'
- standardHeader='false'
- pageHeader='false'
Correct answer: showHeader='false'
Setting showHeader='false' on <apex:page> removes the standard Salesforce header from the rendered page.
Question 4: In Visualforce, how do you reference a static resource named 'myJS' in a <script> tag?
- {!URLFOR('/resource/myJS')}
- {!$Resource.myJS}
- {!URLFOR($Resource.myJS)} (Correct answer)
- {!$Resource['myJS'].url}
Correct answer: {!URLFOR($Resource.myJS)}
URLFOR($Resource.myJS) generates the correct versioned URL for the static resource named myJS.
Question 5: What happens when you set 'readOnly="true"' on an <apex:page>?
- All input fields become disabled
- The page can query up to 1 million rows but cannot perform DML (Correct answer)
- The page cannot call any Apex methods
- The page is cached and not re-rendered on each request
Correct answer: The page can query up to 1 million rows but cannot perform DML
readOnly='true' increases the SOQL row limit to 1 million but prevents any DML operations on the page.
Question 6: Which tag is used to define a reusable section of markup that can be included in multiple Visualforce pages?
- <apex:include>
- <apex:component> (Correct answer)
- <apex:template>
- <apex:fragment>
Correct answer: <apex:component>
<apex:component> defines a custom reusable component that can be referenced by multiple Visualforce pages.
Question 7: What is the correct way to call a method on a Visualforce controller using an action link?
- <apex:commandLink action='{!myMethod}'> (Correct answer)
- <apex:link onclick='{!myMethod}'>
- <apex:outputLink action='{!myMethod}'>
- <apex:commandLink method='myMethod'>
Correct answer: <apex:commandLink action='{!myMethod}'>
<apex:commandLink> with the action attribute set to a controller method expression fires the method on click and performs a full or partial page refresh.
Which Visualforce component is used to display a list of records in a table format with built-in sorting and pagination?