Print this page

How to collapse a VF pageblock section by default on page load

Knowledge Article Number 000181821
Description If we want to collapse a pageblock section when a page is loaded instead of manually collapsing it we can use the following code 
Resolution NOTE: At present, this functionality cannot be implemented via supported Visualforce/Apex methods. What's provided below is provided "as is" and can be used at your own risk, as it makes use of a function that is part of Salesforce's core JavaScript libraries, which are not meant to be used by developers as they may change without further notice.

This can be achieved by including a script statement to show the page block section collapsed by default:

<apex:page >
<apex:pageBlock id="block1">
    <apex:pageBlockSection id="section1" columns="2" collapsible="true" title="Title">
        Example Area
    </apex:pageBlockSection>
    
<script> twistSection(document.getElementById('{!$Component.block1.section1}').getElementsByTagName('img')[0]) </script>
</apex:pageBlock>
</apex:page>





promote demote