PD1 Visualforce Pages 5 — Questions and Answers
Question 1: Which Visualforce component is used to upload files to Salesforce from a page?
- <apex:inputFile> (Correct answer)
- <apex:fileUpload>
- <apex:inputField type='file'>
- <apex:attachment>
Correct answer: <apex:inputFile>
<apex:inputFile> renders a file input element that binds to an Apex Blob property, allowing file content to be uploaded to Salesforce.
Question 2: When using a StandardSetController in Visualforce, which method retrieves the current page's records?
- getRecords() (Correct answer)
- getSelected()
- getResultSize()
- getCompleteResult()
Correct answer: getRecords()
The getRecords() method on StandardSetController returns the list of sObject records for the current page in a paginated list.
Question 3: How do you invoke a JavaScript function from a Visualforce controller action callback?
- Use <apex:actionStatus> with an oncomplete attribute
- Use <apex:actionFunction> with an oncomplete attribute
- Use <apex:commandButton> with an oncomplete attribute
- All of the above (Correct answer)
Correct answer: All of the above
<apex:actionStatus>, <apex:actionFunction>, and <apex:commandButton> all support an oncomplete attribute that executes JavaScript after the AJAX action completes.
Question 4: What is the correct syntax to reference an Apex controller property named 'accountName' in a Visualforce expression?
- {!controller.accountName}
- {!accountName} (Correct answer)
- {!this.accountName}
- {!apex:accountName}
Correct answer: {!accountName}
Visualforce expressions reference controller properties directly without a qualifier, using the format {!propertyName}.
Question 5: Which Visualforce component wraps content to be conditionally shown or hidden using CSS without removing it from the DOM?
- <apex:outputPanel layout='none'>
- <apex:panelGroup>
- <apex:outputPanel> (Correct answer)
- <apex:facet>
Correct answer: <apex:outputPanel>
<apex:outputPanel> wraps content in a div or span and can be hidden via CSS while keeping the content in the DOM, unlike the 'rendered' attribute.
Question 6: In Visualforce, which global variable gives access to the current page URL and its parameters?
- $Page
- $CurrentPage (Correct answer)
- $Request
- $URL
Correct answer: $CurrentPage
$CurrentPage provides access to the current page's URL, name, and query string parameters via properties like $CurrentPage.parameters.
Question 7: What is the effect of setting 'standardStylesheets="false"' on the <apex:page> component?
- Removes Salesforce-specific CSS, allowing fully custom styling (Correct answer)
- Prevents the page from loading third-party CSS files
- Disables inline styles on all child components
- Switches the page to a lightweight mobile stylesheet
Correct answer: Removes Salesforce-specific CSS, allowing fully custom styling
Setting standardStylesheets='false' removes the default Salesforce CSS files from the page, giving developers full control over styling.
Which Visualforce component is used to upload files to Salesforce from a page?