Ok, I have a visualforce button on a standard page layout. I need to refresh the parent page. I tried using JavaScript and placing the redirect in the constructor however it only refreshes my embedded visualforce button. As always any help is appreciated.

<apex:page standardController="SBQQ__Quote__c" extensions="G_UnLockQuoteExt" >

<apex:form >
  <apex:commandButton action="{!UnlockQuote}" value="Unlock Quote" id="UnlockQuote"/>


    function refreshPage(){
           window.top.location.href =  '{!quotePage}';//define this in the controller


public class UnLockQuoteExt {

List<SBQQ__Quote__c> lstLockQuote = new List<SBQQ__Quote__c>();
Private SBQQ__Quote__c soQuote;
Public PageReference quotePage {get; set;}

Public UnLockQuoteExt(ApexPages.StandardController stdController) 
     This.soQuote = (SBQQ__Quote__c)stdController.getRecord(); 
      PageReference quotePage = new PageReference('/'+ soQuote.Id);
            //Return quotePage;

Public  PageReference UnlockQuote(){


    If (lstLockQuote.size() > 0){
      Approval.UnlockResult[] lstUnlock = Approval.unlock(lstLockQuote, false);


  //  PageReference quotePage = new PageReference('/'+ soQuote.Id);
    //      quotePage.setRedirect(true);
    //      Return quotePage;
return null;


1 Answer 1


I believe even if that JS could work, the VF page is delivered from a different domain than the record detail page so your browser would prevent the code because of cross domain security issues. You can verify this in chrome by pressing f12 and checking for console errors.

This post recommends the following:

In your controller/extension:

public class Opp_Ext {
    private ApexPages.StandardController stdController;
    public String redirectUrl {public get; private set;}
    public Boolean shouldRedirect {public get; private set;}

    public Opp_Ext(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        shouldRedirect = false;

    public PageReference doStuffAndRedirect() {
        shouldRedirect = true;
        redirectUrl = stdController.view().getUrl();
        return null;

In the page:

<apex:page standardController="Opportunity" extensions="Opp_Ext" >
    <apex:form >
        <apex:commandButton value="Do Stuff" action="{!doStuffAndRedirect}" rerender="redirectPanel" />
        <apex:outputPanel id="redirectPanel" >
            <apex:outputText rendered="{!shouldRedirect}">
                <script type="text/javascript">
                    window.top.location.href = '{!redirectUrl}';

Essentially instead of "refreshing" or "reloading" the page, you are navigating the user away from the page they are on back to the page they are on. Since this is not attempting to modify the page or any of it's content I think the browsers allow this. This is however, a browser behavior so if a browser considers it unsafe, it may not work.

Disclaimer: since original solution is on StackOverflow I moved the code over instead of marking as duplicate

You must log in to answer this question.

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