Salesforce Visualforce Overview

Visualforce is a technology used in force.com for building custom user interfaces. It is analogous to Java Server Pages (JSP) with Java Server Faces (JSF) in Java technology. Visualforce uses Apex classes (controllers) containing business logic, and visualforce pages and visualforce components containing the presentation.

Visualforce Controllers

Visualforce controller is an Apex class that is used to interact with the force.com database and provide business logic behind Visualforce pages. It uses variables to interact with the presentation layer, and action methods to process user actions via buttons, links, and events. Force.com provides a default controller called standard controller, which replicates the behavior of the native user interface. Custom behavior can be added by creating a custom controller, or adding controller extension to the standard controller.

  • Standard Controller - Force.com provides default controller implementation on every database object existing in the force.com platform including custom objects. No special Apex code is required to create a standard controller, as it's already provided by force.com.

    A standard controller is invoked with the standardController attribute.

    <apex:page standardController="Object">
    

    There are also standard list controllers that help manage a list of objects. The controller to operate on a list is accomplished with the recordSetVar attribute. A list controller can operate on a maximum of 10,000 records at a time and supports pagination for additional sets of records.

    <apex:page standardController="Contact" recordSetVar="contacts">
    
  • Custom Controller - A custom controller is an Apex class built entirely by the user. There is no default functionality, so each and every functionality has to be built from scratch.

    A custom controller is invoked with the controller attribute.

    <apex:page controller="Custom Controller Name">
    
  • Controller Extension - Controller extension allows a developer to use a standard controller, and extend or override the functionality of default implementation with custom Apex code.

    A controller extension is invoked with the extensions attribute.

    <apex:page standardController="Object" extensions="ExtensionClass1, 
    ExtensionClass2">
    

There are two types of methods defined within a controller: Data methods and Action methods.

  • Data methods are defined to set (setter methods) and get (getter methods) data between the page and Controller.
  • Action methods are created to perform business logic and navigate users to a different page.

Visualforce Pages

Visualforce page defines the presentation of a page using a mixture of standard HTML, and XML markup. The XML markup is used to add view components to the page using XML tags defined in the visual force components.

View Components

Visualforce components is a tag library used within Visualforce pages, which begin with the apex: prefix (i.e. ). View components bind the controller to the page, and map data from the controller to the user interface.

Development Environment

As with any force.com development, you may use native Salesforce UI or force.com IDE as a development tool. As a developer, you can enable development mode on the native Salesforce UI to allow syntax highlighting and display an integrated help system. To enable development mode and show view state in development mode, click on your name on Salesforce UI -> My Settings -> Personal -> Advanced User Details -> click on the Edit button. To enable development mode, you must have Customize Application permission enabled.

References

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment