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
Tatiana Cooke 9Tatiana Cooke 9 

Refresh Parent Window of Custom Object from Save on Visualforce Page /Button

Team

I have a custom object for which I have made visualforce buttons that adds attachments to the notes and attachments section. 

The parent page is a custom object. NOT a visualforce page. I know somehow I need to factor in two different domains. = /

Can someone help me with the code?  So far it inserts the record but I have to manually refresh the page to see the attachment. 

User-added image
Visualforce Page
<apex:page standardController="Tenant_Coordination__c" extensions="attachmentsample">
    <apex:form >
    <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
       <apex:commandbutton value="Save" action="{!Save}" onclick="window.top.location='/{!Tenant_Coordination__c.id}'; return true"/>
         <apex:actionFunction name="reloadparent" action="{!reload}" />  
    </apex:form>
</apex:page>
Class
Team

I have a custom object for which I have made visualforce buttons that adds attachments to the notes and attachments section. 

The parent page is a custom object. NOT a visualforce page. I know somehow I need to factor in two different domains. = /

Can someone help me with the code?  So far it inserts the record but I have to manually refresh the page to see the attachment. 



Visualforce Page 
<apex:page standardController="Tenant_Coordination__c" extensions="attachmentsample">
    <apex:form >
    <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
       <apex:commandbutton value="Save" action="{!Save}" onclick="window.top.location='/{!Tenant_Coordination__c.id}'; return true"/>
         <apex:actionFunction name="reloadparent" action="{!reload}" />  
    </apex:form>
</apex:page>

Class

public class attachmentsample {

    public attachmentsample(ApexPages.StandardController controller) {

    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
   
    Public Pagereference Save()
    {
        String accid = System.currentPagereference().getParameters().get('id');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
         
         insert a;
        PageReference parentPage = new PageReference('/' + accid); 
        parentPage.setRedirect(true); 
        return parentPage;
    }   

}

Appreciate any help!

I found something online that might be able to help but I haven't been able to make it work.


If you do not want to add any Javascript in parent window and you have some parameter that is passed to popup window, you can reload parent window using the below script,
function closeWindow(){     
            window.opener.location.href="/{!$CurrentPage.parameters.id}";
            window.top.close();
   }

In my case I am passing Id of the record as parameter to the popup window. Make sure that "Developer Mode" is not enabled. If it is enabled, it will not work.

Link tgo site http://salesforce.stackexchange.com/questions/46192/how-to-refresh-the-parent-window-after-opening-a-pop-up-window-from-inline-page/46195#46195
Best Answer chosen by Tatiana Cooke 9
Deepak GulianDeepak Gulian
<apex:page standardController="Tenant_Coordination__c" extensions="attachmentsample">
<apex:outputPanel rendered="{!refreshPage}">
   <script>
      window.top.location='/{!Tenant_Coordination__c.id}';
   </script>    
<apex:form >
    <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
       <apex:commandLink value="Save" action="{!save}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;"/> 
    </apex:form>
</apex:page>
public class attachmentsample {

public Boolean refreshPage {get; set;}
  

    public attachmentsample(ApexPages.StandardController controller) {
          refreshPage=false;
    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
   
    Public Pagereference Save()
    {
   String accid = System.currentPagereference().getParameters().get('id');
  Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
  insert a;  
  refreshPage=true;
  
  return null;
    }   

}
Update your VF page and Class with the above code!

 

All Answers

Deepak GulianDeepak Gulian
<apex:page standardController="Tenant_Coordination__c" extensions="attachmentsample">
<apex:outputPanel rendered="{!refreshPage}">
   <script>
      window.top.location='/{!Tenant_Coordination__c.id}';
   </script>    
<apex:form >
    <apex:inputfile value="{!myfile.body}" filename="{!myfile.Name}" />
       <apex:commandLink value="Save" action="{!save}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;"/> 
    </apex:form>
</apex:page>
public class attachmentsample {

public Boolean refreshPage {get; set;}
  

    public attachmentsample(ApexPages.StandardController controller) {
          refreshPage=false;
    }
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
   
    Public Pagereference Save()
    {
   String accid = System.currentPagereference().getParameters().get('id');
  Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
  insert a;  
  refreshPage=true;
  
  return null;
    }   

}
Update your VF page and Class with the above code!

 
This was selected as the best answer
Tatiana Cooke 9Tatiana Cooke 9
Worked perfect!

Thank you so much Deepak = D!!