Order of execution in Salesforce Visualforce Page

Order of execution in Salesforce Visualforce Page

1. Constructor of the controller.

2. Action method of the page.

3. Getter methods.

4. If there are any client-side technologies on the page, such as JavaScript, the browser executes them. Example is window.onLoad().

Sample Code:

Visualforce page:

<apex:page controller="Sample" action="{!sav}">
    <apex:outputText >{!mem}</apex:outputText>
</apex:page>

Apex Controller:

public with sharing class Sample {

    public String mem {
       get { return 'getter';}  
       set;
    }

    public sample() {
        mem = 'constructor';
    }
    
    public void sav() {
        mem = 'action';
    }    

}

Output:

Leave a Reply