VisualForce and Apex Class in Salesforce
1. SalesForce provides two ways to build user interfaces. These are Page
Builder and VisualForce. PageBuilder automatically generates pages with
default look-and-feel. VisualForce allows developers to define their own
user interface.
2. VisualForce plays the role of JSP or ASP in SalesForce. It is used to develop
user interface for SalesForce applications.
3. Standard tags are included in VisualForce using apex keyword. As an
example the top level tag in VisualForce is <apex:page>.Rest of the code is
included in <apex:page>. Custom tags use tags use the prefix c:.
4. The syntax to access fields in VisualForce is {!object.Field}. The expression
in between {!} is evaluated. $User gives the details of the user that is
logged in. {!$User.FirstName} displays the first name of the logged in user.
5. A VisualForce page contains HTML, VisualForce components, JavaScript,
Flash and text. All elements need to be well-formed. Visual Force gets
converted into HTML at the server.
6. VisualForce can be used to support other devices like phones, PDAs.
7. <apex:inputfield value=”{!account.name}”/> generates an input element. Based upon the data type of account,name field, appropriate user interface element is displayed (such as text box, pick list). This is an example of data binding.
The value of the name field is displayed in the user interface, and changes
are saved back to the object.
8. <apex:form> is used to display a form. Other VisualForce display elements like text box, checkbox are included in a form.
9. <apex:detail/> is used to print the details page for an object. If the attribute
“relatedlist” is set to false, then related lists are not displayed. Specific
related lists can be added using the VisualForce component <apex:relatedlist>
10. VisualForce supports development mode. Development mode can be
enabled using Setup|My Personal Information}Personal Information. In
development mode, VisualForce provides two main features.
A. Split screen development: In this the browser window is divided into
two parts. The bottom part is used to show VisualForce code.
Changes can be saved and resulting page is displayed on the same
browser window.
B. Creation of new pages by just typing the URL
www.servername.com/apex/PageName where servername is the
SalesForce server that is allocated to you.
11. Page layouts support one or two columns. VisualForce can support more
than two columns.
12. Previous version of VisualForce is S-controls. It is now being phased out.
13. VisualForce components and pages have version numbers. SalesForce
stores the version numbers along with pages. All older versions are
supported.
14. VisualForce elements take attributes similar to XML format. As an example
in the statement below, sidebars and top headers are not displayed.
<apex:page showHeader=”false”>
</apex:page>
<apex:page> also takes an attribute renderAs as input which supports pdf
generation.
15. Record’s id is sent via request parameter, and made available to the page.
In the above example the id identifies the account for which name has to
be displayed.
16. VisualForce consists of three type of elements
A. VisualForce pages: These are used to define the user interface.
VisualForce pages support multiple devices
B. VisualForce components: Standard prebuilt or custom user interface
components available through a tag library
C. VisualForce controllers:<=”” li=””>
17. There are three type of controllers –
Standard Controller
The standard controllers provide access to standard Salesforce.com
behavior.<:apex:page standardController=”Account”>
Custom Controller
Custom Controllers is used for custom behavior or non-standard datasets.<:
apex:page controller=”MyAccount”>
Controller Extensions
Controller Extensions extend the behavior of standard controllers.<:apex:page
standardController=”Contact” extensions=”ClassA, ClassB”>
18. Static resources are accessible through global variables $Resource. It can be
used to access CSS stylesheets, images, flash movies and JavaScript
libraries.
19. Error messages are displayed in pageMessages component and can be
displayed by the statement <apex:pageMessages/>
20. To perform the save operation, the save() method can be invoked on the
object. This is an example of action binding. <apex:commandButton
value=”Save” action={!save}”/>
21. The look-and-feel of VisualForce is managed using StyleSheets. Default
SalesForce look-and-feel can be changed.
22. The size of VisualForce page cannot be more than 15MB.
23. Web Services can also be invoked from VisualForce.