CSA Visualforce Pages 4 — Questions and Answers
Question 1: What keyword makes an Apex variable exempt from being stored in the Visualforce view state?
- static
- transient (Correct answer)
- volatile
- temporary
Correct answer: transient
Variables declared with the transient keyword in Apex are not serialized into the Visualforce view state, reducing its size.
Question 2: Which component is used to display Salesforce error messages and validation rule failures on a Visualforce page?
- <apex:message>
- <apex:messages>
- <apex:pageMessages> (Correct answer)
- <apex:errorPanel>
Correct answer: <apex:pageMessages>
<apex:pageMessages> displays all messages generated for the current page, including validation errors and custom messages added via ApexPages.addMessage().
Question 3: How can a Visualforce page pass a record ID to a custom controller on page load?
- Via a hidden form field
- Through the URL parameter using {!$CurrentPage.parameters.id}
- By using <apex:param> inside <apex:form>
- Using ApexPages.currentPage().getParameters() (Correct answer)
Correct answer: Using ApexPages.currentPage().getParameters()
In the Apex controller constructor, ApexPages.currentPage().getParameters().get('id') retrieves URL parameters passed to the page.
Question 4: Which Visualforce feature allows a page to be used as a PDF document?
- Set renderAs="pdf" on <apex:page> (Correct answer)
- Use <apex:pdf> wrapper tag
- Add ?format=pdf to the URL
- Set contentType="application/pdf" in the controller
Correct answer: Set renderAs="pdf" on <apex:page>
Setting renderAs="pdf" on the <apex:page> tag instructs Salesforce to render the Visualforce page as a PDF document.
Question 5: What is the correct way to call a controller method when a user changes a select list value on a Visualforce page?
- Use <apex:commandButton> inside the select list
- Use <apex:actionSupport> with event="onchange" inside <apex:selectList> (Correct answer)
- Use JavaScript onChange handler calling apex.submit()
- Add reRender to the <apex:selectList> tag directly
Correct answer: Use <apex:actionSupport> with event="onchange" inside <apex:selectList>
<apex:actionSupport> nested inside <apex:selectList> with event="onchange" triggers an AJAX call to the controller when the selection changes.
Question 6: Which standard controller method is used to save a record and return to the detail page?
- save() (Correct answer)
- submit()
- insert()
- commit()
Correct answer: save()
The save() method on the standard controller saves the current record and returns a PageReference to the record's detail page.
Question 7: What is the purpose of the <apex:composition> and <apex:define> tags in Visualforce?
- They create reusable page templates with replaceable sections (Correct answer)
- They define JavaScript libraries to include on the page
- They specify CSS stylesheets for the page
- They create tab components within a page
Correct answer: They create reusable page templates with replaceable sections
<apex:composition> references a template page and <apex:define> fills named sections within that template, enabling page layout reuse.
What keyword makes an Apex variable exempt from being stored in the Visualforce view state?