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
PBS_IC786PBS_IC786 

including visualforce page in detail layout

Anyone know why I have suddenly lost the ability to include a VF page in one of my sections on a custom object page layout?  It used to be there as recently as a few weeks ago and now I only see Scontrols, related lists, custom links, and fields for my object, no more "Pages".

Please advise...

Thanks
Best Answer chosen by Admin (Salesforce Developers) 
jmasl7xjmasl7x
I think I've got that working now.

I wasn't sure how to make the function actually run when the page/frame was loaded - can't figure out how to set the 'onload' attribute of the 'body' element like I could in a regular HTML page (can that be done with a visual force page?)

What've done is to use the syntax
window.onload = function resizeIframe() ...

in my script and then include the script inside the apex:page element:

<apex:page sidebar="false" showHeader="false" standardController="Account">
<script language="javascript">
window.onload = function resizeIframe() {
var thisWindow = window.name;
if(thisWindow){
var iframes = parent.document.getElementsByName(thisWindow);
if (iframes && iframes.length == 1) {
var height = document.body.scrollHeight;
iframes[0].style.height = height + "px";
}
}
}
</script>
<apex:pageBlock >
<apex:pageBlockTable value="{!account.Contacts}" var="contact">
....
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

All Answers

London BenLondon Ben
You are not alone...

I asked the same thing of one of the VF core developers at the Dreamforce conference in London just recently. Simple answer - you cannot do this now with the summer 2008 release except by 'including' your VF page within an S-Control (type = url...)

You can then include a bit of javascript which dynamically resizes your scontrol in your vf page - so it works reasonably well...

Apparently the functionality you (and I) want is in the roadmap.
mcrosbymcrosby
Thanks for the heads up. I was trying to figure this out today as well.
jmasl7xjmasl7x
"You can then include a bit of javascript which dynamically resizes your scontrol in your vf page - so it works reasonably well..."

Is there an example or explanation anywhere of how to do this?
London BenLondon Ben
Hi,

Here's a bit of javascript I use to dynamically change the size of the S-Control... very useful...

function resizeIframe() {
var thisWindow = window.name;
if(thisWindow){
var iframes = parent.document.getElementsByName(thisWindow);
if (iframes && iframes.length == 1) {
var height = document.body.scrollHeight;
iframes[0].style.height = height + "px";
}
}
}

Message Edited by London Ben on 07-24-2008 01:11 AM
jmasl7xjmasl7x
Thanks Ben,

I'll give that a try.
jmasl7xjmasl7x
I think I've got that working now.

I wasn't sure how to make the function actually run when the page/frame was loaded - can't figure out how to set the 'onload' attribute of the 'body' element like I could in a regular HTML page (can that be done with a visual force page?)

What've done is to use the syntax
window.onload = function resizeIframe() ...

in my script and then include the script inside the apex:page element:

<apex:page sidebar="false" showHeader="false" standardController="Account">
<script language="javascript">
window.onload = function resizeIframe() {
var thisWindow = window.name;
if(thisWindow){
var iframes = parent.document.getElementsByName(thisWindow);
if (iframes && iframes.length == 1) {
var height = document.body.scrollHeight;
iframes[0].style.height = height + "px";
}
}
}
</script>
<apex:pageBlock >
<apex:pageBlockTable value="{!account.Contacts}" var="contact">
....
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

This was selected as the best answer
London BenLondon Ben
Hi,

I've not 'tested' your code - but you are going about it exactly the right way with window.onload (to my best knowledge anyhow)

I probably should have mentioned this when I posted the example script - but well done for figuring it out...
jmasl7xjmasl7x
LOL. I didn't want to be a pain by asking something like "so where exactly should I put this code..." ;-)

Anyway, it appears that the ability to add a Visual Force page to a Page Layout has now been restored. Does anyone know what's happening/happened here?

John
XactiumBenXactiumBen
I didn't realise you could do something like this.  This is exactly what I could have done with when I first started using Visualforce.

To me, it seems like the Pages selection in the page layout is only available when you use a standardController in your visualforce page (same with overriding standard buttons).  Anyone know if this is a Developer Edition only feature?


Message Edited by XactiumBen on 08-05-2008 08:17 AM
London BenLondon Ben
Just to clear up...

You CAN include a VF page in a 'page layout' so long as the standard controller is used (so if you use standardController="Account" then you may add this VF page to an Account Page Layout...

What you will find - is that despite your cleverness in achieving this - it's just being embedded in an Scontrol effectively anyway... ie. the size of the 'frame' is subject to the same conditions as an sControl - and you user will experience the 'VF' page being loaded after the main page (same as an Scontrol)...

SO - big deal... just put whatever page you like inside an sControl - use whatever 'controller' you like then... functionality is the same (ie. not perfect - but ok)

As I stated originally - proper support for VF pages in page layouts is some point in the future - from the mouth of the one of the VF lead developers (at dreamforce london 08)
pmbpmb
I am brand new to Salesforce and apex development. I created a visualforce page using a custom controller but now can't figure out how to put it inside an S-Control like you mention. How do I do that?

I see there is a reference in S-Controls to a visualforce page.

{!$ObjectType.ApexPage}

But how do I set that to a specific page?

{!$ObjectType.ApexPage}="test";
    didn't work (where my visualforce page name is "test")

Any help is appreciated.

jmasl7xjmasl7x
pmb,

in my case I just created a 1-line S-Control of type 'URL' containing the relative address of the Visual Force page plus the Id of the Account:


Code:
apex/SFA_KeyDecisionMakers?id={!Account.Id}

where 'SFA_KeyDecisionMakers' is the name of my Visual Force page.

The effect of this seems to be that a window (iFrame?) is created within the page layout and that window shows the Visual Force page.

Regards

John

London BenLondon Ben
John...

That's exactly what I mean...

The effect is the same as including a visual force page directly in a page layout (standard controller)...

Seems at the moment it's pretty half-baked - but it works.

With the inclusion of the bit of javascript earlier - you can dynamically resize the 'frame' so as it fits to content rather than the predetermined size (which I usually set to 1px so as it looks a little smoother visually as the 'page' is loading)
jmasl7xjmasl7x
Ben,

yes, I have your Javascript code in my VF page.

Oddly, I'm finding that the ability to add a Visual Force directly to a page layout (rather than wrapping it in an S-Control) seems to have been switched off again - although the VF Page I'd already included a few weeks ago still seems to be working.

Regards

John
pmbpmb
Thanks John, that worked. However I found it better in our situation to create a new VisualForce Tab and point the to the VF page with the custom controller.

pmb
OhngOhng

Hi folks

 

The JavaScript code that was presented earlier works so long as the S-Control is not encapsulated in a collapsed section. When it's in a collapsed section the height of the control is 0 pixels.

 

To counter this I've changed the properties of the section so that it's about tall enough to accomodate the S-Control; I've added scroll bars; and I've added the following condition to the middle of the script:

 

            var height = document.body.scrollHeight;
            if (height > 10)
            {
                iframes[0].style.height = height + "px";
            }

 

Note that this JavaScript only works for S-Controls. VisualForce pages have a slightly different security model, and the outer information isn't available to the code.

 

Paul

NaishadhNaishadh

Hi,

 

I am getting "Access is denied" error for the following line.

 

parent.document.getElementsByName(thisWindow);

 

 

Pleaes help!

 

 

Vikash TiwaryVikash Tiwary

Hi jmasl7x,

 

"parent.document.getElementsByName(thisWindow)" inside if does not alert anything and there after execution stops if u find any answer to this please let us know.

Thanks.

jmasl7x wrote:
 
I think I've got that working now.

I wasn't sure how to make the function actually run when the page/frame was loaded - can't figure out how to set the 'onload' attribute of the 'body' element like I could in a regular HTML page (can that be done with a visual force page?)

What've done is to use the syntax
window.onload = function resizeIframe() ...

in my script and then include the script inside the apex:page element:

<apex:page sidebar="false" showHeader="false" standardController="Account">
<script language="javascript">
window.onload = function resizeIframe() {
var thisWindow = window.name;
if(thisWindow){
var iframes = parent.document.getElementsByName(thisWindow);
if (iframes && iframes.length == 1) {
var height = document.body.scrollHeight;
iframes[0].style.height = height + "px";
}
}
}
</script>
<apex:pageBlock >
<apex:pageBlockTable value="{!account.Contacts}" var="contact">
....
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>