I have these action functions:

<apex:actionFunction name="save" action="{!SaveAccount}" oncomplete="executeSD();" status="sub-status"/>
<apex:actionFunction name="executeSD" action="{!saveARecord}" status="sub-status">
<apex:actionFunction name="save_and_new" action="{!SaveAccount}" oncomplete="SN_JS();" status="sub-status"/>
<apex:actionFunction name="SN_JS" action="{!saveDifferentRecord}" status="sub-status"/>

The action functions 'save' and 'save_and_new' calls the same apex class function but differs on the oncomplete function call. I realized that the apex functions {!saveARecord} and {!saveDifferentRecord} can be merged in my apex controller class and all i need is to determine which action function is used. How can I detect which action function is being used or how should I write that in my apex controller?


You can pass a parameter to depending on which method you call. Here is an example of how to use action functions with params.

<!-- Page --> 
<apex:actionFunction name="executeSD" action="{!saveARecord}" status="sub-status">
    <apex:param name="saveStatus" assignTo="{!state}" value="" />

<apex:actionFunction name="SN_JS" action="{!saveARecord}" status="sub-status"/>
    <apex:param name="saveStatus" assignTo="{!state}" value="" />

<apex:actionFunction name="save" action="{!SaveAccount}" oncomplete="executeSD('save');" status="sub-status"/>
<apex:actionFunction name="save_and_new" action="{!SaveAccount}" oncomplete="SN_JS('saveNew');" status="sub-status"/>

<!-- Controller -->
public static Sting state { get; set; }

public PageReference saveARecord() {
    if(saveStatus == 'save') {
        //redirect to the save
    } else if (saveStatus == 'saveNew') {
        //redirect to save and new

You can pass a parameter from the Action function and in the Apex class

you can check for that parameter and perform the check according to that.

First Create a property in Apex Class. which will look like below

public static Sting paramFromJS { get; set; }

Define the Action function like below.

<apex:actionFunction name="SN_JS" action="{!saveDifferentRecord}" status="sub-status">
     <apex:param name="paramCheck" assignTo="{!paramFromJS}" value="" />

Call the action function from the JavaScript and pass the parameter which function is being called.


Now, in the apex class put the check with this parameter.

//..Common Lines
If(paramFromJS == 'Save'){
 //.., Logic Here
}else if(paramFromJS == ''){
 //.. Logic Here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.