I don't know how to put this question, so I will just start with the code I have:


global with sharing class MyController {
    public String variableOne{get;set;}

    public MyController(ApexPages.StandardController stdController) {

    public PageReference methodTwo() {
        System.debug('Variable value from methodTwo is '+ variableOne); 
        return null;

    public PageReference methodThree() {
        System.debug('variable value from methodThree is '+ variableOne);
        return null;

    global static String methodOne(String s1){
        return s1+'123';



<apex:page standardController="Account" extensions="MyController">
<c:ScriptsComponent id="scriptsComponent"/>
<script type="text/javascript">
    var records;
    function functionOne(){
        console.log('Entered the functionOne method');
            console.log('result->' + JSON.stringify(result));
            records = result;
                console.log('result we got back from controller is '+records);

    <p onClick="functionOne(); return false;">Click Here</p>
    <apex:form >
        <apex:actionFunction name="setValueJS" action="{!methodTwo}">
            <apex:param name="parm1" assignTo="{!variableOne}" value=""></apex:param>
        <apex:actionFunction name="methodOneJS" action="{!methodThree}">


My Testpage is sending a variable to the methodOne in Controller and it returns the string by appending 123 and then I set this to a variable on the controller using methodTwo defined by actionFunction and then trying to retrieve this variable from methodThree..

But this is what happening:

  1. I never see the debug line in methodTwo priting.
  2. debug line in methodThree always says that the variable value is null
  3. This might be javascript or jquery but the page reloads after i click on the p element

3 Answers 3


Notice that your @RemoteAction is static and hence cannot modify page state, which you are trying to access from your other methods. If you wish to modify page state, do not use a static method.

  • I cannot remove static from methodOne beause it needs to be invoked using RemoteAction.. Any other alternative??
    – javanoob
    Mar 23, 2015 at 15:27
  • setValueJS method which is calling the non-static methodTwo but still methodThree is having null reference for the variable..
    – javanoob
    Mar 23, 2015 at 15:28
  • I knew that it has nothing to do with static vs instance. Thanks for your time Adrian looking into it.
    – javanoob
    Mar 24, 2015 at 13:18

Use reRender="" attribute in methodTwo actionFunction like this :

<apex:actionFunction name="setValueJS" action="{!methodTwo}" reRender="">
        <apex:param name="parm1" assignTo="{!variableOne}" value=""></apex:param>

Try doing same with methodThree as well.


Finally I was able to find the solution..

What was happening is the below two lines are not executed in sequence.


To solve this, I added onComplete attribute for the actionFunction 'setValueJS' to execute the methodOneJS

Not sure why it was running asynchronously.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .