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
sundar84sundar84 

How to refresh the page from the visual force snippet?

Hi Friends

 

I have attached the  Visual force Snippet in one custom object. The  Visual force snippet information will stored in one object. This object  have master detailed relationship with  above object. 

 
If I click the save button in the visual force snippet , the information will saved into the child object. After refresh the page manually  I can see the child object information. some information will update into parent object.  I would like to refresh the whole page when click the save button in the Visual force snippet. please any one Suggest me to resolve this requirement 
 

 

Thanks

Sundar

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Are you referring to a Visualforce page embedded in a standard view page?

 

If so, I think you'll need to take a two step approach to this:

 

(1) Once the save button is clicked, as well as saving the record, set a boolean property in the controller to true.

(2) When rendering the Visualforce page, render out some javascript if the boolean property is true.  This javascript reloads the main page.

 

Something like:

 

Controller:

 

 

public Boolean refreshPage {get; set;}

// set the value to false in the constructor
public MyController()
{
   refreshPage=false;
}

public PageReference save()
{
  // do save
  refreshPage=true;

  return null;
}

 

 

 

Page:

 

 

<apex:outputPanel id="refresh" rendered="true">
 <apex:outputPanel id="refresh1" rendered="{!refreshPage}">
  <script>
   window.top.location='/{!myObj.id}';
  </script>
 </apex:outputPanel>
</apex:outputPanel>

 

 

 

All Answers

bob_buzzardbob_buzzard

Are you referring to a Visualforce page embedded in a standard view page?

 

If so, I think you'll need to take a two step approach to this:

 

(1) Once the save button is clicked, as well as saving the record, set a boolean property in the controller to true.

(2) When rendering the Visualforce page, render out some javascript if the boolean property is true.  This javascript reloads the main page.

 

Something like:

 

Controller:

 

 

public Boolean refreshPage {get; set;}

// set the value to false in the constructor
public MyController()
{
   refreshPage=false;
}

public PageReference save()
{
  // do save
  refreshPage=true;

  return null;
}

 

 

 

Page:

 

 

<apex:outputPanel id="refresh" rendered="true">
 <apex:outputPanel id="refresh1" rendered="{!refreshPage}">
  <script>
   window.top.location='/{!myObj.id}';
  </script>
 </apex:outputPanel>
</apex:outputPanel>

 

 

 

This was selected as the best answer
sundar84sundar84

Yes

 

Visual force page has embedded with one custom object detailed page. when i click the save button the whole page will need to refresh.. 

 

You mentioned refresh flag in save method..  in visual force page  you wrote java script. i have one doubt. the object page reference will come in save method?

 

window.top.location='/{!myObj.id}';

  window.top.location='/{!Purchase_Order__c.id}'; shall i use like this?

 

Thanks

Sundar

bob_buzzardbob_buzzard

Yes - that is the id of the record that you are currently viewing.

sundar84sundar84

 

Thanks  bob,, its working..

 

 

DevelopersDevelopers

Hi Bob,

 

I have an issue in my project. Below is the scenario:

 

We have one visual force page is embedded in the standard page layout of the Orders(custom object). In that we have custom buttons called Remake/Repair/New Case. For these three actions, a new case is created. Here, my problem is,

 

when i click on any of those three custom buttons, if i am in service console, that case should open in a new subtab. If i am in standard sales console, it should redirect to the case created screen. Also, the page should refresh after that particular action.

 

I am facing the issue for auto - refresh of the page. Kindly support me in this.

 

Thanks in advance.

 

Regards,

Kumar

Animesh DattaAnimesh Datta
Hi All,

I have a button on Case Layout. On click of this button Visualforce page opens up in a new window. there is one button one button "OK" on the VF page. on click of this Command button VF page closes and few fields are updating back to Case. I can see fields are updating when I refresh the Case manually. I want refresh case automatically while clicking on the "OK" button and page closes.

Note: I am not using Service Console.

Kindly Help!!

Regards,
Animesh
Bart DebruyneBart Debruyne
Hi all,

​Same problem here.  I created a component with AllowDML="True" and a button to update the description field.  I added the component to a blank VF-Page.
On the standard account pagelayout, I added the VF-Page (with the embedded component).  
When I press the button from the component, I would like to refresh the standard account page (like F5)

I found below url, but this is only working for VF-Pages and not for standard salesforce pagelayouts

https://developer.salesforce.com/page/Controller_Component_Communication.

Please Support me in this,

Thanks in advance.
Bart

 
Nilesh Khandge 11Nilesh Khandge 11
Hi Please check below sample code:
Controller:

public class testmeController

{
    public Contact oContact{get;set;}
    public Boolean refreshPage{get;set;}
   
    public testmeController()
    {
        oContact = new Contact(id='0035C000007lD5q');
        refreshPage = false;
    }
   
    public void doDML()
    {
        System.debug('Inside doDML==>');
        oContact.title = String.valueOf(System.now());
       update oContact;
       
        refreshPage = true;
    }
}
VF Page:

<apex:page controller="testmeController" sidebar="false" showHeader="false">
<script language="javascript" type="text/javascript">
function closeVFP() {
 
self.close();
//window.opener.location.reload(true);
  //  window.close();
       
}
 
   
</script>
 
<apex:form >
  <apex:commandButton action="{!doDML}" value="Transfer to back office" reRender="refreshPanel"/>
  </apex:form>
  <apex:outputPanel id="refreshPanel">
  
  <apex:outputPanel rendered="{!refreshPage}">
 
        <!-- This panel is only shown when the controller wants the parent page to perform a 'reload' -->
        <script>
            
            self.close();
            top.parent.window.opener.location.href = "/0035C000007lD5q"; //contactID
 
        </script>
    </apex:outputPanel>
    </apex:outputPanel>
</apex:page>
 
Anh Tran 43Anh Tran 43
You can do something like code below. It will automatically refresh the salesforce page after finihsing running the visualforce page. If you want to have a button on the visual page, just add the button and call java script below.

<apex:page standardController="Drawing__c">  
    <flow:interview name="Update_Drawing_Name_To_Each_Item">
...
        <apex:param name="varDrawingName" value="{!Drawing__c.Id}" />
    </flow:interview>
    <script>
        self.close();
        window.parent.location.href='/{!Drawing__c.Id}';
    </script>
</apex:page>