function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BBeairdBBeaird 

Ajax rerender after controller record update

I feel like maybe I don't understand the purpose of "rerender."  I want to be able to click a button that calls a method in my controller.  The method then calls out to a webservice to grab a value.  The method then updates the record.  Finally, the fields should be refreshed on the page.   From looking at countless examples, here is the code I've come up with.   The problem is that nothing is being rerendered after the controller method finishes.  If I refresh the page manually, I see the updated fields.  How can I make the fields refresh without having to manually force it?

 

Page

 <apex:commandButton value="test" status="myStatus" action="{!testing}" reRender="theblock"/>

  <apex:actionStatus startText="(processing...)" stopText="" id="myStatus" />

 

 

<apex:pageBlock id="theblock" >
<apex:outputField value="{!Asset.Current_Hours__c}"/>

 

 

 

 

Controller

public void testing(){
     

updateSingleRecord(obj.Id);       //Method that does a webservice call and also updates Current_Hours field on the record.

       
    }

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

I checked your case and It was working for me , only thing that I was not updateing using webservice method. But i will suggest you do like this

Way 1 : Return type of action in controller change it to pagereference and return like this

 

return ApexPages.currentPage();

 

 

 

Way 2 if you only want to rerender one section

<script>

function callAction()

{

jsTesting();

return false;

 

}

</script>

 

<apex:actionFunction action="{!testing}" reRender="theblock" name="jsTesting"  />

<apex:commandButton value="test" status="myStatus"      onlcik="return callAction();"  />

 

All Answers

Shashikant SharmaShashikant Sharma

I checked your case and It was working for me , only thing that I was not updateing using webservice method. But i will suggest you do like this

Way 1 : Return type of action in controller change it to pagereference and return like this

 

return ApexPages.currentPage();

 

 

 

Way 2 if you only want to rerender one section

<script>

function callAction()

{

jsTesting();

return false;

 

}

</script>

 

<apex:actionFunction action="{!testing}" reRender="theblock" name="jsTesting"  />

<apex:commandButton value="test" status="myStatus"      onlcik="return callAction();"  />

 

This was selected as the best answer
BBeairdBBeaird

I found my problem.  It wasn't changing upon rerender because I was saving a copy of the Asset object rather than the actual Asset object that has everything bound to it and is gotten in my controller extension with objAsset= (Asset)controller.getRecord();

 

Once I switched things around to deal directly with that object, everything rerendered perfectly.