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
Sonya Dhand 3Sonya Dhand 3 

Return to Original Page when Clicking on Custom Button?

Hi

I have a custom button on Case object that when clicked on starts a flow .  What I want to do is close the pop up window when the flow finishes and return to the orignal page which is refreshed so the record is updated with the new data .

I have this code on my button which is calling a flow and the following vf page forceclose to close the window but now I need it to refresh the page.  It is currently refreshing the home page and not the page where i call the flow from i.e my Case record

 
<apex:page showChat="false" showHeader="false" sidebar="false" applyBodyTag="false" applyHtmlTag="false">
<html>
    <head>
        <title>ESCAPE</title>
        <script>
        
            function closeWindow(){      
            window.opener.location.href="/{!$CurrentPage.parameters.id}";
            window.top.close();
      
            }
        </script>       
    </head>
    <body onload="closeWindow()">
      
   
      
    
 
       
    </body>
</html>
</apex:page>


And my button custom button code is 
 
/flow/Restart_Case_Milestones?CaseID={!Case.Id}&retURL=https://cs86.salesforce.com/{!Case.Id}


 
Stephanie DodsonStephanie Dodson
Assuming your custom button is set to open/display in the existing window from where the button was clicked, your button code should end like:

/flow/Restart_Case_Milestones?CaseID={!Case.Id}&retURL=/{!Case.Id}
Sonya Dhand 3Sonya Dhand 3
Hi  -  That doesn't refresh the page either.

Actually the code for my custom button is calling the vf page to close the pop up window , but once this is closed I want the whole page to refresh so the new data inputted by the flow can be seen by the user without them having to manaually refresh

/flow/Restart_Case_Milestones?CaseID={!Case.Id}&retURL=/apex/forceclose
Stephanie DodsonStephanie Dodson
Correct, it won't refresh the page, it will redirect to the flow and then redirect back to the case (if you open in existing window instead of new window) which will show any updates that were made to the case during the flow.  This is the simplest way to accomplish this.  


Because of cross domain issues with a standard page and visualforce page, you can't refresh the standard parent page from the child visualforce page.


If you must open the flow in a new window, the only way I have found to accomplish the refresh is to embed the flow in a visualforce page that has the close behavior on finish in it.  Then for your custom button, use an onclick javascript button that launches the child window and on an interval, checks if that child window is closed and if it is, then it will refresh the page.  Example of javascript button below:

{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')} 


var sfid = "{!Case.Id}"; 
window.childWin = window.open('/apex/VFPAGENAMEe?id=' + sfid, 'VFPAGENAME', 'height=450,width=1500,location=yes,menubar=no,status=no,toolbar=no'); 
window.intervalId = window.setInterval('window.checkIfChildWindowIsClosed()', 5*1000); 

//add check function to window 
window.checkIfChildWindowIsClosed = function() 

if(window.childWin.closed) 

window.clearInterval(window.intervalId); 
window.parent.location.href = window.parent.location.href;