Contents[Hide]

Visual force controllers

Standard controller only:

<apex:page standardController="object_name__c" >

Extension:

<apex:page standardController="object_name__c" extensions="pn_ObjectNameDetailsController" >

Custom:

<apex:page controller="pn_CreateLicenseController" >

Where pn is a short of project name.
It is good practice to name your custom pages and their controllers with project or component name.

Controler extension example

/**
* ===================================================================
* Controller for VF page: newOrder
* @author   Pawel Wozniak, This email address is being protected from spambots. You need JavaScript enabled to view it.
* @version  V1.1
* @since    2012-08-25, last edit: 2012-12-05
* ===================================================================
*/

public with sharing class newOrderController {

    /****************************************/
    /***** Controller global variables ******/
    /****************************************/
    // Constants

    // Variables
    private objectName__c orderObj; //Object for standard controller
    ApexPages.StandardController stdController; // Standard controller
    
    // Variables with default get set methods
    
    /****************************************/
    /**** Custom controller constructor *****/
    /****************************************/
    public newOrderController(ApexPages.StandardController controller) {
        this.stdController = controller;
        this.orderObj = (objectName__c)stdController.getRecord();
    }
    
    /*************** Getters ****************/
    /*** Passing values to VS Page fields ***/
    /****************************************/
    
    
    /*************** Setters ***************/
    /****** Reading values from field ******/
    /***************************************/


    /********** Immediate actions ***********/
    /***** Actions executed on page load ****/
    /****************************************/

    
    /*************** Buttons ****************/
    /*** Actions invoked by custom buttons **/
    /****************************************/

    public PageReference doSave() {
        stdController.save();
        return new PageReference('/apex/somePage');
    }

    /*********** Command links **************/
    /*** Actions invoked by comand links ****/
    /****************************************/
      

    /****************************************/
    /*** Class specific helper functions ****/
    /****************************************/

    /**
    *  Class description - what it do
    *
    *  @param inputParamName what this parameter means
    *  @return what is returned by class
    *  @see webpage link or reference to documntation where more inforamtion can be found
    */
    public String className (String inputParamName) {
        // do something
        return output;
    }
}

Best Practices

Use Transient keyword on variables which values will be only displayed and not edited on VF Page it reduce View State and speed up page load.
It is mainly useful for collections which are passed to VF Page to display their values as table or text.

   
© Paweł Woźniak