Calling multiple apex methods from visualforce page using Javascript?

If you need to call multiple apex controller method with sequence (like complete one by one) then using multiple ActionFunction tags you can do so by leveraging the oncomplete attribute of the ActionFunction.

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

The JavaScript invoked when the result of an AJAX update request completes on the client.

<apex:page sidebar=”false” showHeader=”false” controller=”testApexClass”>
<apex:form >
<apex:actionFunction name=”callMethod1″ action=”{!apexMethod1}” oncomplete=”callMethod2();” />
<apex:actionFunction name=”callMethod2″ action=”{!apexMethod2}” oncomplete=”callMethod3();” />
<apex:actionFunction name=”callMethod3″ action=”{!apexMethod3}” oncomplete=”callMethod4();” />
<apex:actionFunction name=”callMethod4″ action=”{!apexMethod4}” oncomplete=”callMethod5();”/>
<apex:actionFunction name=”callMethod5″ action=”{!apexMethod5}” oncomplete=”callMethod6();”/>
<apex:actionFunction name=”callMethod6″ action=”{!apexMethod6}” oncomplete=”alert(‘All the apex methods completed’);” />

// kick it off


public with sharing class testApexClass {

public testApexClass() {

public string apexMethod1() {
return ‘success1’;

public string apexMethod2() {
return ‘success2’;
public string apexMethod3() {
return ‘success3’;
public string apexMethod4() {
return ‘success4’;
public string apexMethod5() {
return ‘success5’;
public string apexMethod6() {
return ‘success6’;


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 *