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

If you need to call apex controller method after the visualforce page load then its possible with the help of javascript.


A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request

using actionFunction we can call the apexclass method with the help of javascript after the page load like

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

//Build your logic
<apex:form >
<apex:actionFunction name=”callMethod1″ action=”{!apexMethod1}”  />

finally call the below script, then its called to apex class method after the page initialised (after the page loaded)
// kick it off


Apex Class:

public with sharing class testApexClass {

public testApexClass() {

public string apexMethod1() {
return ‘success1’;


Written by 

3x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published.