Refresh Page After OnClick

  • I have a custom VF page acting as a button. When the button is refreshed, a checkbox is either checked or unchecked. All that works fine, but I cannot figure out a way to reload the page after the function is called. Can anyone help? Thanks,

    <script src="/soap/ajax/35.0/connection.js"/>
    
    <script type="text/javascript">
        function Escalate(){
          var confirmMsg = confirm("Are you sure you want to escalate to the Client?");
            var c = new sforce.SObject("Case");
          if(confirmMsg == true){
              c.id = "{!Case.Id}";
              c.Escalate_to_Client__c = true;
            sforce.connection.update([c]);  
          }
          else{
              return false;;  
          }
          window.location.reload();
          }
    
        function Rescind(){
          var confirmMsg = confirm("Are you sure you want rescind the escalation to the Client?");
            var c = new sforce.SObject("Case");
          if(confirmMsg == true){
              c.id = "{!Case.Id}";
              c.Escalate_to_Client__c = false;
            sforce.connection.update([c]);  
          }
          else{
            return false;
          }
            window.location.reload();
        }
    </script>
    
        <apex:form >
        <center>
            <apex:pageBlock mode="maindetail" >
                <apex:pageBlockButtons location="Top" >
                <div style="width:400px;">
                    <apex:commandButton value="Escalate To Client" onClick="Escalate()" rendered="{!IF(Case.Escalate_To_Client__c = false, TRUE,FALSE)}"/>
                    <apex:commandButton value="Rescind Escalation To Client" onClick="Rescind()" rendered="{!IF(Case.Escalate_To_Client__c = true, TRUE,FALSE)}"/>
                </div>
                </apex:PageBlockButtons>
            </apex:PageBlock>
    

    Are you talking about having the VF insert reload your standard Page Layout?

    Try changing `window.location.reload` to `window.top.location.reload`.

    @AdrianLarson -- Thanks. I tried that but it still doesn't reload. The field does change, but I have to manually reload the page to see the change. Any idea why?

    @J.Neilan Open up your console. Getting any error messages? Put some logging before and after the redirect.

    I created a chat room to further discuss.

  • This functionality works for me. If I include the below Visualforce Page in a Page Layout and click the button, it refreshes the whole page.

    <apex:page standardController="Case">
        <apex:form>
            <apex:commandButton value="Reload" onclick="window.location.top.reload();" />
        </apex:form>
    </apex:page>
    

    That implies the following should work:

    <apex:commandButton value="..." onClick="..."
        oncomplete="window.top.location.reload()" />
    

    Failing that, perhaps try:

    <apex:commandButton value="..." onClick="..."
        oncomplete="window.top.location = {!URLFOR($Action.Case.View, Case.Id)}" />
    

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM