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
DianeMDianeM 

Strange behavior with a Visualforce page embedded in a standard Salesforce layout

I am seeing different behaviors for my Visualforce page depending on whether the user who runs it has development enabled or not.

 

I have two users that have the same role and profile but one has development mode turned on and the other does not.

 

I have a layout for a custom object that includes a Visualforce page as part of the standard layout.  This Visualforce page has an Action button.  The action button performs some logic and then returns a PageReference of the original page with redirect set to true so that the whole page refreshes.

 

When I click the action button as the user who has development enabled, everything works as I expect it to.  When I click the action button as the user who does not have development enabled, the refreshed page is display in the area that used to occupied by the Visualforce page.  The entire Salesforce page is now displayed inside the original page.

 

Has anyone else seen anything like this?  I have read some posts about the Visualforce page and the main page running in different domains and that makes sense - except in this case, if I have development enabled everything works.

 

I also see this same behavior (Salesforce page displayed within the Salesforce page) if I have an unhandled exception in the controller extension for my Visualforce page.  In this case, it doesn't matter whether I am running as a user with development privileges or not.

Best Answer chosen by Admin (Salesforce Developers) 
DianeMDianeM
Thanks for your help with this Jill.  Using the commandLink instead of the button worked just fine.  And making it look like a button at this point is not a high priority - the link works just fine.

All Answers

jwetzlerjwetzler

Are you using javascript at all?  What does your button look like?

 

Sounds like there's a window.top being called.

DianeMDianeM

Jill,

 

thank you for your really quick response.  I have no javascript in my Visualforce page at all - it is pure Visualforce.  The action button is defined in the Visualforce with the following statement.

 

<apex:commandButton action="{!allocate}" value="Allocate"

 

 

The code in the controller performs some logic and then returns a PageReference.

 

 

pageRef = new PageReference('/'+refId.subString(0,15)); pageRef.setRedirect(true);

 

 

The refid in the code snippet above is the id of the object.  I had to do a substring at one point to make sure that the id was valid.  I haven't tried without the substring in Summer '09.  The pageRef is returned.  I have also tried using the controller to set the page reference.

 

pageRef = stdController.view().setRedirect(true);

 

 

The behavior here is the same.  If I have development enabled, everything works as expected.  If I don't have it enabled, I get a Salesforce page inside a Salesforce page.

 

Thanks,

 

Diane

ABHIKSARKARABHIKSARKAR

Hi , i m also facing the same issue with developer mode off.

 

I have a visualforce page with command buttons . I have used onclick javascript functions on this buttons .

 

function mthd_newpage()
{ window.parent.location.href='/home/home.jsp';
}

This piece of code works fine with developer mode on. But with developer mode off , the same piece of code is not working. I m unable to find the reason for it. 

can somebody help pls.

 

Thanks 

 

jwetzlerjwetzler

that's because developer mode puts your page in an iframe.

 

You should be returning the page you want from your action method instead of using javascript.

DianeMDianeM

Happy 4th Jill,

 

So does the iframe explain the issue I described.  my action method is returning the main page but it is being rendered inside the original page - except when I am in developer mode, then it works.

 

Diane

jwetzlerjwetzler

If you're not using javascript like the person who replied below me, then I don't have an explanation for it.

 

Can you try to create a small, standalone example for me that I can just copy and paste into a test org?  This is the first of heard of this behavior when there is no javascript involved.

 

Also if you could test in a couple of different browsers and see if the behavior is any different that would help too.

DianeMDianeM

Hi Jill,

 

I hope you had a good holiday.  I have tested this issue on both IE8 and Firefox 3.0.11.  When I click my button as a user with development turned on, everything works as I expect.  When I click my button as a user with development turned off, I see the page within a page.  My objective here is to have the entire page refreshed after I perform the action.

 

I have created a simple Visualforce page and controller extension based on the Account object.  With this simple test I experience the same issue.

 

Here is the controller extension.

public with sharing class TestControllerExtension {

private ApexPages.StandardController stdController = null;

private Account acct = null;

public TestControllerExtension(ApexPages.StandardController controller) {

this.stdController = controller;

acct = (Account)stdController.getRecord();

}

public PageReference test() {

PageReference pageRef = null;

String refId = acct.id;

pageRef = new PageReference('/'+refId.subString(0,15));

pageRef.setRedirect(true); return pageRef;

}

}

 

 

...and here is my test Visualforce page.

<apex:page standardController="Account" extensions="TestControllerExtension">

<apex:pageBlock >

<apex:messages >

</apex:messages>

<apex:actionRegion >

<apex:form id="theform" >

<apex:commandButton action="{!test}" value="Test" />

</apex:form>

</apex:actionRegion>

</apex:pageBlock>

</apex:page>

 

 

On the account layout, I insert a new section and then I put this Visualforce page in that section.  The section is defined as a single column.  When I open an account I see the Test button in the new section.  Clicking the Test button displays the behavior I have described above.

 

I don't know if this is a feature that isn't supported, or I am trying to refresh the whole page in the wrong manner or this is a bug.  BTW, I also see this behavior (page within the page) if an exception is thrown in the extension.

 

Please let me know if you think I should submit a case for this.

 

Thanks for your help.

jwetzlerjwetzler

So I believe there is a bug here, but I think the bug is that in developer mode, your top page should NOT be refreshed.  It should work the way that it works with developer mode turned off.  The inline page on your layout is in an iframe, so what happens in the iframe should have no affect on your outer page.

DianeMDianeM

Ok - I agree it certainly does seem like a bug - except I think it is with the non-developer mode.  Either that or I should not be allowed to put an action button or link on a visualforce page that is going to be inside a standard salesforce page.

 

Do you know of anyway I can force a refresh of the main page after I complete an action in my Visualforce page that is embedded?

 

Thanks for your help with this.  Should I submit a case?

 

Regards,

 

Diane

jwetzlerjwetzler

No, that's not the way iframes should work.  If you do a redirect inside of an iframe, it should not be touching the enclosing page.

 

Normally you could just use javascript to handle the refresh but you're right, that's not going to work with separate domains, since your inline page will be served from a different domain than your outer page.

 

You should be able to get this to work by using commandLink instead of commandButton (you can use CSS to style it like a button if you really need it to look like one) and then set target="_top".  I think that will work.

 

Not much point in logging a case because even if the bug is fixed it's not going to give you what you want.

DianeMDianeM
Thanks for your help with this Jill.  Using the commandLink instead of the button worked just fine.  And making it look like a button at this point is not a high priority - the link works just fine.
This was selected as the best answer
ritikakhatri1.394602279912887E12ritikakhatri1.394602279912887E12
Hi,
Did u get the solution?? M facing a similar issue...

Can anyone help.Its urgent

Thanks
Bill Gravelle SABill Gravelle SA
Im having this issue right now. Is there any workaround?