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
mxalix258mxalix258 

CommandButton to reload entire window

Hi,

 

I have a piece of code that is a command button that links to another page, the problem is since the visualforce page is embedded as an iFrame, it only loads within the iframe. How can I get it so that it reloads the entire window with the URL that I am looking to go to?

 

    <apex:pageblockButtons location="top">
                <apex:commandbutton action="/a02/o" title="View All" value="View All"> 
                </apex:commandbutton>
    </apex:pageblockButtons>

 

Best Answer chosen by Admin (Salesforce Developers) 
Naidu PothiniNaidu Pothini
Inside controller:
	
        public String redirectUrl { get; set; }
        public Boolean shouldRedirect { public get; private set; }

	public pageReference redirectMethod()
	{
                shouldRedirect = true;
		redirectUrl = '/a02/o';
		return null;
	}


Visualforce Page:

	<apex:pageblockButtons location="top">
      
      <apex:commandbutton action="{!redirectMethod}" title="View All" value="View All" rerender="redirectPanel"/>

      <apex:outputPanel id="redirectPanel"> 
            <apex:outputText rendered="{!shouldRedirect}" escape="false"> 
                <script type="text/javascript"> 
                     window.top.location.href = '{!redirectUrl}'; 
                </script>
            </apex:outputText>
      </apex:outputPanel>         

    </apex:pageblockButtons>

 this should work. it worked for me.

All Answers

Naidu PothiniNaidu Pothini
<apex:pageblockButtons location="top">
<apex:commandbutton action="/a02/o" title="View All" value="View All" rerender="redirectPanel">
</apex:commandbutton>
</apex:pageblockButtons>

<apex:outputPanel id="redirectPanel">
<apex:outputText rendered="{!shouldRedirect}" escape="false">
<script type="text/javascript">
window.top.location.href = '/a02/o';
</script>
</apex:outputText>
</apex:outputPanel>

 You could try something like this.

mxalix258mxalix258

I forgot to mention that I am utilizing a custom controller, would that affect the usability of your solution? It gave me an error of "unknown property"

Naidu PothiniNaidu Pothini
<apex:pageblockButtons location="top">
                <apex:commandbutton action="{!redirectMethod}" title="View All" value="View All" rerender="redirectPanel"> 
                </apex:commandbutton>

<apex:outputPanel id="redirectPanel"> 
      <apex:outputText escape="false"> 
          <script type="text/javascript"> 
               window.top.location.href = '{!redirectURL}';
          </script>
      </apex:outputText>
</apex:outputPanel>

</apex:pageblockButtons>

 If so you could use a redirect method in the controller which will have the url value to redirectURL field which is being use for redirection.

 

Let me know if it still doesnot work.

mxalix258mxalix258

My visualforce page isn't able to recognize the variable "redirectURL" is there something wrong with the method I put in my controller?

 

public String redirectMethod ()
{
   String redirectURL = 'https://test.my.salesforce.com/a02/o';
   return redirectURL;
}

 

Naidu PothiniNaidu Pothini
public string redirectURL { get;set; }

public void redirectMethod ()
{
   redirectURL = 'https://test.my.salesforce.com/a02/o';
}

 try this.

mxalix258mxalix258

Thanks a lot for your help so far! It just seems to be perpetually loading now. It never  loads the whole page. Here is the code:

 

<apex:form >
    <apex:pageBlock title="New Candidates" rendered="{!AND(NOT(ISNULL(newestcandidates)),newestcandidates.size>0)}">  
    <apex:pageblockButtons location="top">
                <apex:commandbutton action="{!redirectMethod}" title="View All" value="View All" rerender="redirectPanel"> 
                </apex:commandbutton>
<apex:outputPanel id="redirectPanel"> 
      <apex:outputText escape="false"> 
          <script type="text/javascript"> 
               window.top.location.href = '{!redirectURL}';
          </script>
      </apex:outputText>
</apex:outputPanel>         
    </apex:pageblockButtons>
          <apex:dataTable value="{!newestcandidates}" var="can" rowClasses="evencell, oddcell"
          columns="5" width="100%">
          <apex:column >
                <apex:facet name="header">Name</apex:facet>
                <apex:outputLink value="/{!can.id}" target="_top">{!can.Name}</apex:outputLink>
            </apex:column>
          <apex:column >
                <apex:facet name="header">Status</apex:facet>
                <apex:outputText value="{!can.Status__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Interest Areas</apex:facet>
                <apex:outputText value="{!can.Interest_Areas__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Years of Experience</apex:facet>
                <apex:outputText value="{!can.Years_of_Experience__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Created Date</apex:facet>
                <apex:outputText value="{!can.CreatedDate}"/>
            </apex:column>
        </apex:dataTable>
        </apex:pageBlock>
        <apex:pageBlock title="New Candidates" rendered="{!OR(ISNULL(newestcandidates),newestcandidates.size=0)}">
                <apex:outputLabel value="No records to display"></apex:outputLabel>
        </apex:pageBlock>
 </apex:form>

 

Naidu PothiniNaidu Pothini
<apex:form >

  <apex:pageBlock title="New Candidates" rendered="{!AND(NOT(ISNULL(newestcandidates)),newestcandidates.size>0)}">  
    
    <apex:pageblockButtons location="top">
      
      <apex:commandbutton action="{!redirectMethod}" title="View All" value="View All" rerender="redirectPanel"/>

      <apex:outputPanel id="redirectPanel"> 
            <apex:outputText escape="false"> 
                <script type="text/javascript"> 
                     window.top.location.href = '/a02/o';
                </script>
            </apex:outputText>
      </apex:outputPanel>         

    </apex:pageblockButtons>

    <apex:dataTable value="{!newestcandidates}" var="can" rowClasses="evencell, oddcell" columns="5" width="100%">

      <apex:column >

        <apex:facet name="header">Name</apex:facet>
        <apex:outputLink value="/{!can.id}" target="_top">{!can.Name}</apex:outputLink>

      </apex:column>

      <apex:column >

        <apex:facet name="header">Status</apex:facet>
        <apex:outputText value="{!can.Status__c}"/>

      </apex:column>

      <apex:column >

        <apex:facet name="header">Interest Areas</apex:facet>
        <apex:outputText value="{!can.Interest_Areas__c}"/>

      </apex:column>

      <apex:column >

        <apex:facet name="header">Years of Experience</apex:facet>
        <apex:outputText value="{!can.Years_of_Experience__c}"/>

      </apex:column>

      <apex:column >

        <apex:facet name="header">Created Date</apex:facet>
        <apex:outputText value="{!can.CreatedDate}"/>

      </apex:column>

    </apex:dataTable>

  </apex:pageBlock>

  <apex:pageBlock title="New Candidates" rendered="{!OR(ISNULL(newestcandidates),newestcandidates.size=0)}">

    <apex:outputLabel value="No records to display"></apex:outputLabel>

  </apex:pageBlock>

</apex:form>

 can you try this small change.

mxalix258mxalix258

When I load the visualpage, it automatically reloads the target URL (/a02/o) without clicking anything....any thoughts on why that would be?

Naidu PothiniNaidu Pothini
Inside controller:

public String redirectUrl { get; set; } public pageReference redirectMethod() { redirectUrl = '/a02/o'; return null; } Visualforce Page:
<apex:pageblockButtons location="top"> <apex:commandbutton action="{!redirectMethod}" title="View All" value="View All" rerender="redirectPanel"/> <apex:outputPanel id="redirectPanel"> <apex:outputText escape="false"> <script type="text/javascript"> window.top.location.href = '{!redirectUrl}'; </script> </apex:outputText> </apex:outputPanel> </apex:pageblockButtons>

 try this. if this doesnt work... we should go with onclick event..

 

 

mxalix258mxalix258

No such luck....for some reason it still seems as though the page is continually loading back and forth. I'm sorry, I didn't realize this would be so complicated!

Naidu PothiniNaidu Pothini
Inside controller:
	
        public String redirectUrl { get; set; }
        public Boolean shouldRedirect { public get; private set; }

	public pageReference redirectMethod()
	{
                shouldRedirect = true;
		redirectUrl = '/a02/o';
		return null;
	}


Visualforce Page:

	<apex:pageblockButtons location="top">
      
      <apex:commandbutton action="{!redirectMethod}" title="View All" value="View All" rerender="redirectPanel"/>

      <apex:outputPanel id="redirectPanel"> 
            <apex:outputText rendered="{!shouldRedirect}" escape="false"> 
                <script type="text/javascript"> 
                     window.top.location.href = '{!redirectUrl}'; 
                </script>
            </apex:outputText>
      </apex:outputPanel>         

    </apex:pageblockButtons>

 this should work. it worked for me.

This was selected as the best answer
mxalix258mxalix258

Thank you so much!