Find your content:

Search form

You are here

How to get the updated values after an APEX call from Javascript


I am currently calling an APEX method (in a controller) with variables from Javascript. I would like to reflect the changes made in the controller in the page. I am using an apex:actionFunction to call the method and then I am using another actionFunction to reRender a block of the page. I believe the changes are taking place in the controller (I can make logs of the changes) and I think the rerender is working, but the new values are not being shown on the page. They will only be shown if I force a refresh by pressing a button, or similar.

I have been looking at a number of examples, but I have not found anything useful for this particular issue. Here is a summarized version of my code:


<apex:actionFunction name="rerenderInfoBlock" rerender="InfoBlockContainer" />


<apex:actionFunction action="{!runControllerMethod}" name="newCustomerRecruitMonitorSelected" rerender=""> 
    <apex:param name="monitorId" assignTo="{!monitorId}" value="" />


alert("{!objectReference.changedProperty}");//this property will not be changed


public PageReference runControllerMethod(){
    //get the parameters etc and make a change to a few properties
    return null;

Is there some step I am missing? I am guessing I have to tell the javascript to somehow go back to the server and get the updated values, but I am not sure how to do this... Would be great if any answers contained links to references. Thanks.

Edit, Here is the output panel that I am trying to rerender:

<apex:outputPanel id="InfoBlockContainer">
    <apex:pageBlock id="InfoBlock" rendered="{!showBlock == true}">

Attribution to: lindon fox

Possible Suggestion/Solution #1

Several possibilities here.

  • I'm not sure an actionFunction that has no controller action is guaranteed to re-poll the controller. You should just move your rerender property of "InfoBlockContainer" to your newCustomerRecruitMonitorSelected actionFunction.
  • Your JS code should be calling newCustomerRecruitMonitorSelected(parameterVar), not runControllerMethod(parameterVar) -- the "name" param of an actionFunction becomes the JS function, while JS knows nothing about the controller param names. (To reduce errors like this on my own part, I generally name my controller methods and my actionFunctions the same thing, where appropriate.) This error would show up in a JS console/debugger.
  • a JS actionFunction method fires instantly, and asynchronously does the rerender. Therefore, your alert statement will always return the unchanged property, since it's pretty much a guarantee that the browser will fire it before the async request returns and does the rerender.

Without a little more detail about what you're rerendering and how, it's hard to diagnose further, but start with those.

Attribution to: jkraybill
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content