Home SALESFORCEAPEX Calling multiple apex methods from visualforce page using Javascript?

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’;


You may also like

Leave a Comment