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
Connor CainConnor Cain 

load visual force tab when selected

Is It possible to only have an Apex method called only when the tab it is under is selected? The code is displaying a query under each tab and I am trying to avoid a Apex CPU Limit reached.
Raj VakatiRaj Vakati
You can do it only if the tab is custom visualforce tab 
  1. Create a vf page tab 
  2. Load the apex method using any partial page load techniques like partial load , render etc ..

 
Connor CainConnor Cain
hey Raj, by custom visual force tab do you mean i cant use <apex:tab>?
Raj VakatiRaj Vakati
my bad .. i understand question wrong 

You can do it like below 


<apex:tab label="AppConfig" name="AppConfig" id="AppConfig" onclick="onClickAppConfig()" />

<apex:actionFunction action="{!apexMethod}" name="onClickAppConfig" rerender="myTab"> <!-- add any parameters if you want --> </apex:actionFunction>

 
public class Controller_name{

   public void apexMethod(){
    //logic
   }
}

 
Connor CainConnor Cain
i added this and it didnt work, it isnt rendering anything, its just blank now. here is my code
 
<apex:tab label="Account" name="AccountTab" id="AccountTab" onclick="onClickAccount()">
                <apex:form>
                <apex:actionFunction action{!getAccountList} name="onClickAccount" rendered="AccountTab">
                	<apex:pageBlock title="Account">
                    	<apex:pageBlockTable value="{!AccountList}" var="Account"> 
                                      	<apex:column headerValue="API Name" value="{!Account.ApiName}"/>
                        	<apex:column headerValue="Label" value="{!Account.Label}"/>
                        	<apex:column headerValue="Data Type" value="{!Account.DataType}"/>
                        	<apex:column headerValue="Picklist" value="{!Account.PickLists}"/>
                        	<apex:column headerValue="Description" value="{!Account.Description}"/>
                        	<apex:column headerValue="InLineHelpText" value="{!Account.InLineHelpText}"/>
                    	</apex:pageBlockTable>                          
                	</apex:pageBlock>
                </apex:actionFunction>
                </apex:form>
            </apex:tab>