You need to sign in to do that
Don't have an account?
Dynamic Resizing of Visualforce pages on Pagelayout (example shown)
Hi all,
I recently came across a problem where I had a Visualforce page displayed on a page layout and the height of it needed to be defined according to how many records were returned in the list I was displaying. After doing a little poking around, I came up with a cool solution I am happy to share. First step, the div that displays the Visualforce page is actually given the id of the Visualforce page itself - so you need to first find the id of the Visualforce page. Next, create an S-Control to do an onload resizing of this particular div element based on a query defined within the script itself. Below is an example of resizing a Visualforce page displayed on the account that displays a list of active contacts.
<script type="text/javascript" src="/js/functions.js"></script> <script src="/soap/ajax/12.0/connection.js"></script> <script type="text/javascript"> window.onload = resizeWindow(); function resizeWindow(){ //Ensure a valid Salesforce connection. sforce.connection.sessionId = "{!API.Session_ID}"; //Set account id of account used in contact query. var accountid = "{!Account.Id}"; //Retrieve a list of contacts on the account that are not inactive. result = sforce.connection.query("Select Id from Contact where AccountId = '"+accountid+"' and Inactive__c != true"); //Create a pixel variable to assign the dynamic height. This example adds an extra 50px to display the top part of the page in the case no records are retrieved. contactsize = result.getArray("records").length*30+50+'px'; //Retrieve the height of the div the Visualforce page lies in and set it to the new dynamic size. The id is the actual id of the Visualforce page. top.document.getElementById("066P00000008bke").height = contactsize; } </script>
I thought S-Controls were deprecated are no longer supposed to be used?
Thank you!!! This helped!
Brilliant solution!
I wish we could still make s-controls to implement this. Do you have any solutions without using s-controls?
David
(Not speaking for everyone, but from my own research)
When you really think about it, we have 2 only options to embed custom pages on a standard page layout:
I guess another alternative is to insert an invisible VisualForce page onto the page layout, which will popup a VisualForce page in a separate window to the user on page load. In this way, the window size isn't limited to a fixed size setting on the page layout.
Did you find a proper solution for this? Can you please send me any links if you have any? I'm facing the same problem.
Thanks
http://salesforcehacks.blogspot.com/2014/12/resizing-embedded-vf.html