0

Setup:

I have a VF page embedded in standard page layout, "source." when the user clicks a button that is in the VF Page, he should get sent to a new page "destination".

Problem: the destination page is opening within the VF section of the page layout- "source" This only occus when the user is not in development mode.

VF

<apex:pageBlock rendered="{!IF(ISNULL(record) , true , false)}">
  <apex:pageBlockSection columns="1" title="Analysis"/>
    <center>
     <apex:commandButton value="Create Strategies" action="{!createNewRecord}"/>
    </center>
</apex:pageBlock>

Controller:

 public pageReference createNewRecord(){
        PageReference p;
        String s = '/a0K/e?CF00Ne0000000fqjP=' + this.record.name + '&retURL=' + this.record.id;
        p = new PageReference(s);
        p = p.setredirect(true);
        return p;

    }

1 Answer 1

2

You need to tell the page to have the parent page redirect, not the VF page that you are currently interacting with.

Add this your VF page

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

And change your commande button to

<apex:commandButton value="Create Strategies" action="{!createNewRecord}" rerender="redirectPanel"/>

And make these adds/changes in your controller

public boolean shouldRedirect           {get;set;}{shouldRedirect = false;}
public string url                       {get;set;}


public PageReference createNewRecord(){
     url = '/a0K/e?CF00Ne0000000fqjP=' + this.record.name + '&retURL=' + this.record.id;        
     shouldRedirect = true;
     return null;
}
0

You must log in to answer this question.

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