PD1 Visualforce Pages 4 — Questions and Answers
Question 1: Which Visualforce component enables partial page updates (AJAX) without a full page refresh?
- <apex:actionRegion>
- <apex:actionSupport> (Correct answer)
- <apex:outputPanel>
- <apex:actionFunction>
Correct answer: <apex:actionSupport>
<apex:actionSupport> adds AJAX behavior to a parent component, calling a controller action and re-rendering specified targets on an event.
Question 2: What is the purpose of the 'reRender' attribute in Visualforce AJAX components?
- It forces the entire page to reload after an action
- It specifies the IDs of components to refresh after a server action completes (Correct answer)
- It renders the component on the server instead of the client
- It re-executes the SOQL query for the page
Correct answer: It specifies the IDs of components to refresh after a server action completes
The reRender attribute takes a comma-separated list of component IDs to refresh via AJAX after the server action completes.
Question 3: Which Visualforce controller type allows you to work with records that are NOT based on a single sObject?
- Standard Controller
- Extension Controller
- Custom Controller (Correct answer)
- List Controller
Correct answer: Custom Controller
A Custom Controller is a full Apex class that replaces the standard controller, allowing you to define arbitrary logic not tied to a single sObject.
Question 4: How do you pass a parameter from a Visualforce page to a controller method using <apex:actionFunction>?
- Use the 'param' attribute on the action function tag
- Use <apex:param> child elements inside <apex:actionFunction> (Correct answer)
- Use the URL query string parameters
- Use the $CurrentPage.parameters global variable in the controller
Correct answer: Use <apex:param> child elements inside <apex:actionFunction>
<apex:param> elements nested inside <apex:actionFunction> bind JavaScript variable values to controller properties before the action fires.
Question 5: Which Visualforce tag is used to define sections within a <apex:pageBlock> that display fields in a two-column layout?
- <apex:pageBlockSection> (Correct answer)
- <apex:panelGrid>
- <apex:sectionHeader>
- <apex:detail>
Correct answer: <apex:pageBlockSection>
<apex:pageBlockSection> creates a two-column section within a pageBlock, automatically organizing fields into label-value pairs.
Question 6: What is the view state in Visualforce, and what is its size limit?
- A server-side cache of SOQL results; limited to 5MB
- A hidden form field storing component state between postbacks; limited to 170KB (Correct answer)
- A browser cookie storing user session data; limited to 4KB
- An in-memory Apex variable store; limited to 6MB heap
Correct answer: A hidden form field storing component state between postbacks; limited to 170KB
Visualforce view state is a hidden HTML form field that preserves component state across postbacks, with a 170KB maximum size.
Question 7: Which keyword in Apex reduces view state size by preventing a variable from being serialized into the view state?
- static
- transient (Correct answer)
- volatile
- final
Correct answer: transient
Marking an Apex variable as 'transient' excludes it from serialization into the view state, reducing the view state payload.
Which Visualforce component enables partial page updates (AJAX) without a full page refresh?