Home SALESFORCEAPEX How to call the Apex methods from visualforce page before the page load

How to call the Apex methods from visualforce page before the page load?

If you need to call apex controller method before the visualforce page load then its possible with the help of action attributes in apex:page.

A single Visualforce page. All pages must be wrapped inside a single page component tag.

action ApexPages.Action The action method invoked when this page is requested by the server. Use expression language to reference an action method. For example, action=”{!doAction}” references the doAction() method in the controller. If an action is not specified, the page loads as usual. If the action method returns null, the page simply refreshes. This method will be called before the page is rendered and allows you to optionally redirect the user to another page. This action should not be used for initialization.


<apex:page sidebar=”false” showHeader=”false” controller=”testApexClass” action=”{!apexMethod1}”>
<TITLE> New Document </TITLE>
<META NAME=”Generator” CONTENT=”EditPlus”>
<META NAME=”Keywords” CONTENT=””>
<META NAME=”Description” CONTENT=””>

//Build your logic


Apex Class:

public with sharing class testApexClass {

public testApexClass() {

public string apexMethod1() {
return ‘success1’;


You may also like

Leave a Comment