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
Rajiv B 3Rajiv B 3 

Unable to Refresh Current case from VF page

"Add PR Contact" is case detail page button it will create a Contact from VF page and same will be liked to the current case. It is working as expected but curent case is not getting automatically refreshd to see changes in the case. 

Below is the VF page script
 
<script

language="JavaScript" type="text/javascript">
function CloseAndRefresh(){
window.opener.location.href="/{!$CurrentPage.parameters.id}";
      window.top.close(); 
  }
</script>

<apex:pageBlockButtons >
<apex:commandbutton action="{!save}" id="button" oncomplete="javascript:CloseAndRefresh()" value="Save"/>   </apex:pageBlockButtons>

Could you please suggest me where I have to make changes to refresh the case automatically.

Appreciate for your suggestions. 
pconpcon
Can you try
 
<script>
    function refreshPage() {
        window.location.reload();
    }
</script>

<apex:commandButton action="{!save}" id="button" onComplete="refreshPage()" value="Save" />

I don't really see a reason you have to open a new page and close the current one if it's the same page.

Alternately, you could use an ActionRegion and reload the region and re-fetch the data in the Visualforce controller.
Rajiv B 3Rajiv B 3
Pcon, 
Actually users need to see a contact crate page as separate window where they can see the current case for required information to pass into the case page. 

I tried with your suggesion but didn't work.

Thanks
pconpcon
Ok, so your contact create page is opened as a seperate window popup?  If so, then you're going to have to look into dispatching events between your popup and the page.

https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
Rajiv B 3Rajiv B 3
That is true.. VF page will be opened as separate window where we pass required information some are from the current case. 

VF page has controller that will create the contact and same will update into the current case upon clik save...i am good till here. 

Upon  clik save on opened VF page it will create contact in the back end and add the same into the current case and vf will close. 
But the problem is current case is not getting auto refreshed to see the lates changes (Updated contact details) where every time required manual refresh the case. 
pconpcon
Yep, so what you'll want to do is have the popup window send information back to the parent window after submission.  You can also delegate the closing of the popup to the parent window.  Below is an example in pure HTML / js but it should give you an idea of how to use it
 
<html>
     <head>
          <title>Popup parent</title>
     </head>
     <body>
          <button onclick="buttonClick()">Open Popup</button>
          <script>
               var popup = undefined;

               function buttonClick() {
                    popup = window.open('/test/popup.html');
               }

               function receiveMessage(event) {
                    var data = JSON.parse(event.data);

                    if (data.action === 'close' && popup !== undefined) {
                         popup.close();
                    }
               }

               window.addEventListener("message", receiveMessage, false);
          </script>
     </body>
</html>
 
<html>
     <head>
          <title>Popup</title>
     </head>
     <body>
          <h1>I'm a popup!</h1>
          <p>I'll redirect/close in 10 seconds</p>
          <script>
               function makecallback() {
                    window.opener.postMessage(JSON.stringify({action: "close"}), '*');
               }

               window.setTimeout(makecallback, 10000);
          </script>
     </body>
</html>