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 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 6x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *