Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am trying to complete a VF page section that my sales-staff will be utilizing to add information to custom fields when a condition is met inside of the Account object. I have the custom page built and deposited into the account layout; but my final hurdle is what happens when the VF section is saved. When the 'Save' command button is clicked, the entire page is deposited into the VF section. The VF page when accessed directly works perfectly; it's only when the section is used inside of the larger page layout is the 'window inside window' effect seen. An F5 rectifies this; and returns the section back to normal but I cannot for the life of me figure out how to avoid this extra step. I modeled the code after this example found on developerforce:

http://developer.force.com/cookbook/recipe/dynamically-updating-a-page

Any help would be appreciated.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

From the recipe change the save button from

<apex:commandButton value="Save" action="{!save}"/>

to

    <apex:commandLink value="Save" action="{!save}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;">

Since commandlink offers a target attribute I make use of it and make the command link exactly like the button using styleclass and style attributes

I tried even the command button with onclick approach but the child page constantly reloaded with the side bar and headers and did not look like it was inline. The commandlink is something I have worked hence the solution above, but it could be done using commandbutton if tweaked a bit more. Since we have what is required I did not push futher:)

share|improve this answer
    
Thanks rao! That worked perfectly. –  Ian Allison May 27 at 18:16
    
@Ian Allison please mark it solved when you get some time :) –  rao May 27 at 18:21

An additional mechanism to consider in the event that you can't or don't want to use an <apex:commandLink with the target attribute set to _parent is to use a javascript statement to cause the parent page to refresh itself after successful saving.

The idea here is that you only render the script panel that executes the page refresh at the time you want the outer page to automatically reload (i.e. pressing F5). In this example the script block is displayed after the user clicks save (successfully) and the page inside the iframe (the VF embedded in the page layout) is being rendered back to the browser. The browser executes the now-visible javascript and the outer page is reloaded.

You might also consider setting the showHeader="false" sidebar="false" attributes on the page tag to disable those features if this page is going to be used exclusively embedded in another page layout.

VF Page embedded in a page layout (iframe):

<apex:page standardController="Account" extensions="yourExtensionClass" showHeader="false" sidebar="false">
    <apex:form>

    <apex:pageMessages />

    <apex:outputPanel id="refreshPanel" rendered="{!refreshPage}">
        <!-- This panel is only shown when the controller wants the parent page to perform a 'reload' -->
        <script>
            // force the browser to reload the 'top' page using the current URL
            window.top.location.href = window.top.location.href;
        </script>
    </apex:outputPanel>

    <!-- Your existing stuff -->

    </apex:form>
</apex:page>

The controller extension class:

public with sharing class yourExtensionClass {

    public Boolean refreshPage { get; set; }
    public ApexPages.StandardController stdController { get; set; }

    public yourExtensionClass(ApexPages.StandardController ctrl) {
        stdController = ctrl;

        // initialize the refresh value as false
        refreshPage = false;
    }

    public PageReference save() {

        // use the standard controller's save method
        PageReference pRef = stdController.save();

        if (pRef != null) {
            // set this value last, after successful saving to cause the VF page to show the javascript block
            refreshPage = true;
        }

        return pRef;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.