Вы находитесь на странице: 1из 9

VisualForce Interview Question & Answers

1. When do you use visualforce page?

VisualForce is a WebDevelopment framework, used to design dynamic and attractive user


interfaces.
(Because, we can't customise all the features exist in the standard page layout.)
By using VisualForce, we can design our own customized user interfaces.
2. Which components we can use in visualforce pages?

VisualForce Components:
Each visualforce page contains two components.
1. VisualForce Markup:
It contains a set of VisualForce Tags, has been used to design the user interface.
Each VisualForce Tag is a Dependent Tag, i.e. each starting tag should require an ending tag.
VisualForce Tags are not case sensitive.
Each VisualForce Page Tag should be prefixed with the word "apex".
Ex:
<apex:page>
....
</apex:page>
Each Tag contains one or more attributes, which are used to supply the input values.
2. VisualForce Controller:
It contains the corresponding business logic, using by the visualforce page controles.
It can be implemented by using "Apex, SOQL, SOSL, DML" statements.
Note: A visualforce page can reference one or more controller classes.
3. What will happen if we set the <apex:page readonly=true
A. VisualForce allows us to display max. of 1000 records in a visualforce page by default. We
can't show more than 1000 records in a VF page.
Note: To show more number of records upto 10,000 in a VF page, we need to set the
"ReadOnly" attribute as TRUE in page tag as below.
<apex:page readonly="true">
4.Which API version we are using in the VF page?
Visualforce Version 38.0
5. How to generate page in PDF format?
RenderAs ="Pdf": This attribute is used to display the VisualForce page content interms of a
PDF File.
Syntax: <apex:page RenderAs="pdf">
....
</apex:page>

6. What is the use of renderAS attribute in <apex:page> component?


This attribute is used to display the VisualForce page content interms of a PDF File.
7. All the components are supported in the pdf format?
All The components are supported in pdf format
8.What all the content-types are supported in the VF page?
This attribute is used to display the VF page content as a word document.
Syntax: contentType="application/msword#<FileName>.doc"
Ex:
contentType="application/msword#MyContent.doc"
9. What is StandardController?
Salesforce provides a set of standard methods for each class generated by salesforce.
i.e. It provides a set of readymade methods in each class(Standard / Custom).
Note: Each method / variable / Object inside the class should be referenced as a "Merge Field /
Binding Varibale".
Syntax:
{!<VaribaleName>}
{!<MethodName>}
{!<CollectionName>}
Associating a Standard Controller with a Visualforce Page. To associate a standard controller
with a Visualforce page, use the standardController attribute on the <apex:page> tag and assign
it the name of any Salesforce object that can be queried using the Force.com API.
10. How many standardcontroller we can define in the <apex:page>?

11. What is controller in VF page?


VisualForce provides 3 types of controllers. Which are used to implement the business logicand
can be invoke by using visualforce controls (Ex: Buttons, Picklists, etc).
Standard Controller, Extension controller, Custom Controller
12. When do you Controller?
This attribute is used to specify the custom class name, which can be referenced inside the VF
page.
syntax:
controller = "CustomClassName"
13. How many controller we can define in the VF page?
You can have a standard object controller and multiple controller extensions. I don't think there is
any upper limit on the same.
14. Can a controller have constructor with parameters?
15. What are extensions in VF page?
This attribute is used to specify the extension class name, which contains the custom methods to
be used inside the VF page.
Syntax:

<apex:page standardcontroller="Account" extensions="AccountExtesion">


....
</apex:page>
16. When do you use extensions in VF page?
Extension controller has to be used along with either "StandardController or
CustomController".
Syntax:
<apex:page standardcontroller="Account" extensions="AccountExtesion">
....
</apex:page>
17. If we define Apex class should have constructor with which parameter?
18. What is the difference between <apex:actionFunction>, <apex:actionSupport>,
RemoteAction?

<apex:actionfunction>
By using this Tag, we can invoke the controller action methods from javascript.
Upon invoking the actions, we can show the Process status also.
We can have only one ActionFunction inside the VF page and use the ActionFunction in multiple
place in the page, by defining it as "Global - define in <form> level"
Syntax:
<apex:actionfunction
Name = "FunctionName"
Action = "<ActionMethod Name>"
Rerender = "<Components to Refresh>"
Status = "<ActionStatusControl Id>" />

<apex:actionSupport>
By using this Tag, we can enhance the features of VF tags. So that they can invoke the action
methods from the client side.
Ex:Picklist control (<apex:selectlist>) doesn't have the attribute "Action", to invoke controller
methods by default.
We can use the standard picklist control, by leveraging the features by adding the support to
invoke the action methods.
Syntax: <apex:actionsupport
event ="<Event Name(onchange, onblur)>"
Action ="<Controller Method Name>"
Rerender ="<Components to refresh>" />

RemoteAction
The remote method definition in your Apex controller class. This method definition is written in
Apex, but there are some important differences from normal actionmethods. The response
handler callback function you add to or include in your Visualforce page, written in JavaScript.

19. What are basics rules that we have to check before we invoke a method from
Visualforce page?
20. What is the difference between insert and include and define?
Insert
A template component that declares a named area that must be defined by
an <apex:define> component in another Visualforce page. Use this component with
the <apex:composition> and <apex:define> components to share data between multiple pages.

Include
A component that inserts a second Visualforce page into the current page. The entire page subtree
is injected into the Visualforce DOM at the point of reference and the scope of the included page
is maintained.
If content should be stripped from the included page, use the <apex:composition> component
instead.

Define
A template component that provides content for an <apex:insert> component defined in
a Visualforce template page. See also: <apex:composition> , <apex:insert>
21. What is <apex:actionpooler>?
This tag is used to refresh the Page / Part of the page for the specified time interval.
One the specified time interval is over, it make a request to salesforce to invoke the specified
action method and will refresh the specified component.
Syntax:
<apex:actionPoller
action="<Method Name>"
interval = "Time in Seconds"
Rerender ="<Component to Refresh>" />
22. In action interval is given in which format?
23. What is the difference between pageblockTable, datatable, dataList, repeat?

PageBlock Tag (<apex:PageBlock):


This tag is used to divide the VF page into multiple blocks. In each block we can display the
different content.
Note: A VF Page can have one or more PageBlocks.
Syntax:
<apex:PageBlock title="Title For the PageBlock"
rendered = "TRUE/FALSE">
....
</apex:pageblock>

apex:dataTable
An HTML table thats defined by iterating over a set of data, displaying information about one
item of data per row. The body of the <apex:dataTable> contains one or more column
components that specify what information should be displayed for each item of data. The data set
can include up to 1,000 items, or 10,000 items when the page is executed in read-only mode.
For Visualforce pages running Salesforce.com API version 20.0 or higher, an <apex:repeat> tag
can be contained within this component to generate columns.

apex:dataList
An ordered or unordered list of values that is defined by iterating over a set of data. The body of
the <apex:dataList>component specifies how a single item should appear in the list. The data set
can include up to 1,000 items.

apex:repeat
An iteration component that allows you to output the contents of a collection according to a
structure that you specify. The collection can include up to 1,000 items.
Note that if used within an <apex:pageBlockSection> or <apex:panelGrid> component, all
content generated by a child <apex:repeat> component is placed in a
single <apex:pageBlockSection> or <apex:panelGrid> cell.
This component can't be used as a direct child of the following components:

<apex:panelBar>

<apex:selectCheckboxes>

<apex:selectList>

<apex:selectRadio>

<apex:tabPanel>

24. How many records we can display in the pageBlockTable?

25. If you want more than 1000 records using pageBlockTable how to achive?
26. If you want to display more than 10,000 records using pageBlockTable how to
implement it?

27. What is pagination?

PAGINATION IN VISUAL FORCE:


VisualForce allows us to display max. of 1000 records in a visualforce page by default. We can't
show more than 1000 records in a VF page.
Note: To show more number of records upto 10,000 in a VF page, we need to set the
"ReadOnly" attribute as TRUE in page tag as below.
<apex:page readonly="true">
...
...
</apex:page>
This feature allows us to display the records upto 10,000 in a VisualForce page.
Instead of displaying all the thousands of records in the object in the visual force page at a time,
we can display a set of records, which will improve the performance of the page.
To display a specified number of records in the page, we are using pagination. (Ex: Inbox in
Gmail)
28. In how many ways we can implement pagination?
To implement the pagination in Visual Force, Apex Provides a standard class called as
"StandardSetController", Which provides a set of built-in methods to perform the actions.
Internally it will will get the all the records from the object and store into Cache. and it will pickup the specified records from the cache and display into the page.
29. What is the drawback pagination using SOQL?
30. What is the drawback of pagination using QueryMore?
31. What is advantage of pagination using StandardsetController?
As the number of records increases, the time required for the browser to render them increases.
Paging is used to reduce the amount of data exchanged with the client. Paging is typically
handled on the server side (standardsetcontroller). The page sends parameters to the controller,
which the controller needs to interpret and then respond with the appropriate data set.
33. How to transfer the data from one VF page to another VF page?
34. What is PageReference?
A PageReference is a reference to an instantiation of a page. Among other
attributes, PageReferences consist of a URL and a set of query parameter names and values. ...
To view or set query string parameters and values for a page. To navigate the user to a different
page as the result of an action method. Methods.
35. What is action attribute in <apex:page>?

Attribute Type: ApexPages.Action

The action method invoked when this page is requested by the server. Use expression language
to reference an action method. For example, action="{!doAction}" references the doAction()
method in the controller.
If an action isnt specified, the page loads as usual. If the action method returns null, the page
simply refreshes.
This method is called before the page is rendered, and allows you to optionally redirect the user
to another page.
Important: This action should not be used for initialization or DML.
36. What is the execution order of VF page?

We can request VF page in two ways Get Request: Whenever we click on a link or button or directly hitting the url in address bar we
can open a VF page.
Get Request Order
Postback Request: On a VF page after populating fields if you click on save button certain
action will invoke it is nothing but postback request.
Postback Request Order
37. What is the difference between rendered,reRender,RenderAs?

Rendered
This attribute is used to indicate, whether the PageBlock to be displayed inside the page or not.
Note: By default it contains the value as "TRUE".

reRender
This attribute is used to indicate the component name, to be refreshed after performing the
action.
Syntax:
<apex:commandButton value="Save" action="{!Save}" rerender="<ComponentID>"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
<apex:commandButton value="Search" action="{!DoSearch}"/>

RenderAs
This attribute is used to display the VisualForce page content interms of a PDF File.
Syntax:
<apex:page RenderAs="pdf">
....
</apex:page>

rendered: Accepts true or false. If it is true then component will display on the page, if it is
false then it won't display on the page.
rerender: To refresh certain area of a page based on component id.

renderAs: Used in page tag, We can display VF page in PDF format if we give renderAs =
"PDF".

contentType: Used in page tag, we can download VF page in MS Word/Excel etc. based on
the input to contentType.

38. What is view state?


Creation: In a visualforce page, whenever we use form tag then view state will be created for
the page.
Purpose: Assume that, we need to display the user input form in 3different visualforce pages.
In first and second pages, user has to fill the information and click on Next button. On the final
page, after filling the form if he/she will click on Save button, which ever the information we
filled in the first and second pages should be also saved. View state will store the information
which is filled in first and second page . To maintain the state of the page, we need view state.
Size: All the variables which we use in controller/extensions classes and expressions which are
declared on the page will occupy the space in view state.
Governor Limits: Maximum size of the View State is: 135 KB.
Page Performance:
Whatever the variables information we don't required to maintain the state while navigating to
other pages those variables we can decorate with transient keyword which won't occupy space
in the view state.
Static variables also won't occupy space in the view state.
It is recommended to use only one form tag. If there are multiple form tags hierarchy of the
folder structure increases which will occupy more space.

VIEW STATE:
- View state is an object, which persists the Form data during the postback implementations.
- It preserves the form control's data temporarily in our local system.
- View state data will be stored in the form of "hidden" fields.
- View state will convert the form data in "Base64" encoding format, in-order to provide the
security.
- We can view the view state information in "Page View Source" option from the menu, which
displays when we release the right mouse button on the form.
Note: All variable, and collections and objects defined inside the controller class will be
persisted in "ViewState" object.
Ex:
<input type="hidden" name="at" value="AF6bupNdff7BqLXCDzEkOHF8B0cotGDGtw">
Enable View State In Development Mode: (To track viewstate)
Goto Your Name --> Goto My Settings --> Goto Personal & Expand this.
1. Click on "Advanced USer Details" link
2. Click on "Edit" button
3. Select the Checkbox "Show ViewState in Development Mode"
4. click on "Save" button

Note: We can store max. of 135 KB of data in View State.


If the View state max. size exceeds, then it will raise the exception "View State Limit Exceeds".
To avoid the View State Limit Exceptions, we need to use the keyword "Transient"
We have to define the objects or the variable with the Transient keyword, for which the data need
not to be persist into viewstate.
Syntax: public Transient <Variable Name / ObjectName>;
Ex:
public Transient integer accountNumber;
public Transient string customerName;
public Transient List<Account> lstAccounts;
- The above variable and object's data will not persist in Viewstate.

39. What is the governing limits in the view state?


We can store max. of 135 KB of data in View State.
If the View state max. size exceeds, then it will raise the exception "View State Limit Exceeds".
To avoid the View State Limit Exceptions, we need to use the keyword "Transient"
We have to define the objects or the variable with the Transient keyword, for which the data need
not to be persist into viewstate.
40. Will the view state maintains static variables state?
41. Will the view state maintains the transient variables state?
42. How to overcome view state exception?

Some tips to overcome viewstate limits:1. Use Transient keyword for variables which are storing temporary values.
2. Declare variables as Static wherever possible as they are not included in view state.
3. Refine Your SOQL to Retrieve Only the Data Needed by the Page.
4. Use Custom Objects or Custom Settings to Store Large Quantities of Read-Only Data.
5.Use HTML forms instead <apex:form>.
6.Use HTML components instead of <apex:commandbutton>,<apex:commandlink> ,etc to make
your page stateless which saves hitting view state limits.

Вам также может понравиться