I am really confused as to how to solve this issue I have on a visualforce page. Basically I have a pageblock table with some Opportunity Products displayed. On the onchange event of the fields in the rows I have placed an actionsupport tag that will call a save method then rerender the row so that the updated TotalPrice from the server can be displayed.

My issue is that IF I make change to one of these fields then immediately click a Finish button (this button contains a redirect to the Opp) the redirect is executed instantly, the async call from the onchange event is not completed BEFORE the redirect (since its async) and therefore the Opp is displayed before the Opportunity is updated meaining I have to reload the Opp page to see the updated Amount.

What I want is a way to have the actionsupport tag of the inputfields complete before the redirect of the Finish button is executed. How can I acomplish this???

Please help as I am out of ideas, I have tried several things and they all have not worked.

  • Please add what you have already tried, it will help
    – Saariko
    Apr 25, 2013 at 10:33

2 Answers 2


I think the user clicks on the Save button before the AJAX call is finished and the record is not saved, right? My solution is just to block the input elements on the page while the AJAX call works, and only if it finished - release the inputs. So user can not click on the Save button while your controller works.

Simple controller example:

public with sharing class test1 {
    // We will show some account on the page
    public List<Account> accounts { get; set; }

    public test1(){
        // Reading accounts
        accounts = [Select Id, Name, CustomerPriority__c From Account Limit 3];

    public PageReference someAction(){
        // Your 'save' logic is here ....
        return null;

Visualforce page. I will use JQuery to block the input elements on the page:

<apex:page controller="test1">
    <!-- Dynamically including the jQuery to the page -->
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"/>

    <!-- This is a javascript function that will block and release elements -->
        function blockAllInputs(param){
                jQuery('input[type=button], input[type=submit]').attr('disabled','disabled').removeClass('btn').addClass('btnDisabled');
                jQuery('input[type=button], input[type=submit]').removeAttr('disabled').removeClass('btnDisabled').addClass('btn');

        <apex:pageBlock title="My Block">
                <apex:commandButton value="Save" reRender="none"/>
            <apex:pageBlockTable value="{!accounts}" var="a">
                <apex:column headerValue="{!$ObjectType.Account.fields.CustomerPriority__c.label}">
                        <apex:inputField value="{!a.CustomerPriority__c}" id="myField">
                            <apex:actionSupport event="onchange"

How it will looks like:

enter image description here

  • Great answer, we also do this. Jun 25, 2013 at 12:30

You can do something like this.

Keep a JS variable isOppUpdated and when you change field make this variable false and once the field is updated make it true.

Now when you click on Finish button first check whether isOppUpdated is true or not. Then redirect it accordingly.

I hope you are aware of onClick, onComplete event handlers.

You must log in to answer this question.

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