Dynamically resize VisualForce section in page layout

We have a page layout for a custom object and want to put a Visualforce page as a section in it. However, the height of the content varies, and when I drop the section in, there is a large white space if the content does not fill. How do I deal with this (the part with the big red ‘X’ through it)?

enter image description here


Yes it is possible. See the Update – Success at the bottom:

Old Answer – close but not so much

Resizing the VF Page within a Page Layout is not possible though there is an option on the Page Layout that allows scrollbars for the embedded content.

Another option is to (1) make the “embedded” Visualforce Page a Visualforce Component, and (2) write a VF Page similar to:

<apex:page standardController="Your_Object__c">
    <apex:detail subject="{!Your_Object__c.Id}" relatedList="true"/>
    <c:yourComponent recordId="{!Your_Object__c.Id}" />

Then override the View Standard Button or Link on the Object page with this VF Page.

This option does have some minor downsides in that developers will have to go into the Object from the Setup to change the Page Layout rather than the using the “Edit Layout” link on the top-right. Also Developers will lose the Dev Tools Menu. Again, these are minor issues for Developers, but this could add the functionality you are looking for. It’s worth a try.

Update – Success

VF Pages embedded in a Page Layout come over as iframes, so the solution is to write a VF Page using only <apex:detail .../> to bring over the Page Layout and then have JavaScript (via jQuery) resize all the iframes.


<apex:page standardController="Custom_Object__c">
    <apex:detail subject="{!Custom_Object__c.Id}" relatedList="true"/>  
    <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/>
        var j$ = jQuery.noConflict();
            j$(this).load(function() {
                j$(this).height( j$(this).contents().find("body").height() );

Source : Link , Question Author : kb_ , Answer Author : Scott Pelak

Leave a Comment