I have a team that I'd like to use an edit mode embedded in the standard page layout so they can edit only the selected fields. The save button works but loads the whole page inside the embedded VF page, creating a nesting regression. So how to have the save button bring the user back to the proper top lead url?

VF page code:

<apex:page standardController="lead" extensions="LeadEditExtension">
<apex:form >

        <apex:pageBlock title="New Accounts" mode="edit" >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!SaveLead}" value="save"



            <apex:pageBlockSection title="Progress" columns="2">

enter image description here


2 Answers 2


You could use apex:commandlink to set the target to _top


Add the following code to your Visualforce page, removing the apex:commandbutton:

<apex:commandLink action="{!saveLead}" value="Save" target="_top"/>

If you don't want a link but a button, you can use CSS to style the link to look like a button with the following code:

<apex:commandLink action="{!saveLead}" value="Save" target="_top" styleClass="btn" style="text-decoration:none;padding:4px;"/>
  • I like the styled command link - it seems simple and direct. Is there any functional difference between the save and redirect I found?
    – jaw999
    Mar 14, 2016 at 13:01
  • I'm not sure to be honest. I don't think there is a big difference, functionally. Technical difference is that you are using javascript and the commandlink isn't.
    – Folkert
    Mar 14, 2016 at 13:35
  • the difference I see is a full page reload or just a reload of the inline page. So if there is a field change on the regular layout section as a result of the edits made to the inline section then you'll want to have the full reload.
    – jaw999
    Mar 14, 2016 at 13:42

This saveAndredirect is working. I took it from https://stackoverflow.com/questions/11552514/visualforce-page-embedded-in-a-detail-page-that-needs-to-redirect-to-other-page:

    public class LeadEditExtension {
 private ApexPages.StandardController sc;

    public Boolean shouldRedirect {public get; private set;}
    public String redirectUrl {public get; private set;}
    public LeadEditExtension (ApexPages.StandardController StandardController) {

    //Store a reference to the standard controller
    sc = standardController;
    shouldRedirect = false;


    public PageReference SaveLead() {

    Lead Lead1 =(lead)sc.getRecord();
        PageReference redirecturl = new PageReference('/'+Lead1.id);

        return redirecturl;  


    public PageReference SaveAndRedirect() {
        shouldRedirect = true;
        redirectUrl = sc.view().getUrl();
        return null;


You must log in to answer this question.

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