3

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>
5
  • Are you talking about having the VF insert reload your standard Page Layout? Commented May 17, 2016 at 20:40
  • Try changing window.location.reload to window.top.location.reload.
    – Adrian Larson
    Commented May 17, 2016 at 21:51
  • @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
    Commented May 18, 2016 at 15:06
  • @J.Neilan Open up your console. Getting any error messages? Put some logging before and after the redirect.
    – Adrian Larson
    Commented May 18, 2016 at 15:07
  • I created a chat room to further discuss.
    – Adrian Larson
    Commented May 18, 2016 at 15:38

3 Answers 3

4

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)}" />
0
1

The first answer...

oncomplete="window.top.location.reload()"

was very helpful, thank you!

Here's how I used it in my code (changed labels to protect info):

    <apex:page standardController="Opportunity" >

<script>

    function launchWindow()

    {

    window.open("/apex/Run_My_Flow?id={!Opportunity.Id}");

}

</script>

     <apex:form >

     <apex:commandButton onclick="launchWindow();" value="Click This Button" style="float:right" oncomplete="window.top.location.reload()" />


     </apex:form> 

</apex:page>
0

If you were rerendering part of your form in the command button then remove that instruction as it inhibits (I guess takes precedence) over the oncomplete function. e.g. rerender="panelId"

You must log in to answer this question.

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