Search Here

Introduction to visualforce pages

 Visual Force is a framework that allows developers to build sophisticated, custom user interfaces that can be hosted natively on the Force.com platform. The Visual Force framework includes a tag-based markup language, similar to HTML.


Creating visualforce pages in salesforce:

visualforce is very interesting framework in salesforce. It is a markup language you can use this to develop user interface according to your requirements in salesforce. visualforce runs on Force.com platform.  To design UI you can write visualforce pages and by using controllers you can write business logic to your visaulforce pages.

<apex:page > 

    <h1>Welcome to Salesforce</h1><br/>

    This is your new Page 

</apex:page>

What are the tasks of standard controller?

Standard controllers provides ability to access and interact with structured business data contained in records displays in the proper user interface.

Controlling Data:

<apex:page standardController=”Account”>        // standard object
<apex:page standardController=”customer__c”>    
// custom object

What is Standard List Controllers?

A standard list controller enables you to create Visualforce pages that can display or act on a set of records. Examples of existing Salesforce pages that work with a set of records include list pages, related lists, and mass action pages.

<apex:page standardController="Account" <strong><span style="color: #993366;" data-mce-style="color: #993366;">recordSetVar="accounts"</span></strong>>

Standard list controller provides additional four pagination actions. Those are first, last, next and previous.

We can use standard list controllers with the following objects.

Account, Asset, Campaign, Case, Contact, Contract, Idea, Lead, Opportunity, Order, Product2, Solution, User, Custom Objects.

Standard list controller example:

<apex:page standardController="Account" recordSetVar="accounts">

<apex:form >

<apex:pageBlock >

<apex:pageBlockTable value="{!Accounts}" var="a">

<apex:column headerValue="Account Name">

<apex:outputField value="{!a.name}"/>

</apex:column>

</apex:pageBlockTable>


<!-- pagination actions supported by standard list controller -->

<apex:pageBlockButtons >

<apex:commandButton value="First" action="{!first}"/>

<apex:commandButton value="Last" action="{!last}"/>

<apex:commandButton value="Next" action="{!next}"/>

<apex:commandButton value="previous" action="{!previous}"/>

</apex:pageBlockButtons>

</apex:pageBlock>

</apex:form>

</apex:page>

What is viewState?

ViewState holds state of the visualforce page that holds state that includes the fields, components and controller state. Viewstate data in encrypted and cannot be viewed tools like firebug.

Rendering visualforce page as a pdf

<apex:page  StandardController=”Account ” renderAs=”pdf”>

Below is simple code to rendering a visualforce page as pdf.

<apex:page renderAs=”pdf”>
<center>
<h1>Welocome to Salesforce Tutorial</h1>
</center>
</apex:page>

What is actionPoller tag?

This tag specifies a timer that sends an AJAX update request at specified interval. Minimum interval time to refresh is 5 sec.

Visualforce page Code:

<apex:page controller="actionpollerDemoController">

    <apex:form >

        <apex:pageBlock id="pb">

             <span style="color: #ff0000;" data-mce-style="color: #ff0000;"><strong><apex:actionPoller action="{!dateTimeMethod}" reRender="pb" interval="5"/></strong></span>

                     Hello!!!  Date and Time: <strong><span style="color: #ff0000;" data-mce-style="color: #ff0000;">{!dateAndTime}</span> </strong>

                     <p>Note: Time will refresh fror eevry 5 sec.</p>

         </apex:pageBlock>

      </apex:form>

</apex:page>

actionpollerDemoController.apx

public with sharing class actionpollerDemoController {

public DateTime dateAndTime{

get;

set;

} public void dateTimeMethod(){

dateAndTime = System.now();

}

}





Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.