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
mtanmtan 

Help with VF Page Render Time Improvement

Hi,

 

One of our user groups is using a custom VF page to consolidate their field work information in a form of a survey.

The problem with the existing VF page they are using is that it takes ages to load the default issue and action information for the option they have selected for a question item.

 

I am relatively new to Salesforce and was asked to look into and address this performance issue. 

 

Appreciate the help, thanks.

 

VF Page Code

<apex:page standardController="Checklist_Item__c"  extensions="CollectChecklistItemsExtension" sidebar="false">
    <apex:form > 
        
        <apex:pageBlock title="Edit Checklist Item Data" id="idPageBlock1" mode="edit">
            
            <apex:pageMessages /> 
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!ChecklistItems}" var="c" id="idPageBlockTable1">
                
                <apex:column value="{!c.Id}" rendered="false" />
                
                <apex:column value="{!c.Question_Category__c}" headerValue="Category" />                
                
                <apex:column value="{!c.Question__c}" /> 
                
                <apex:column headerValue="Answer">
                    <apex:outputPanel id="idAnswerOutputPanel" >
                        <apex:inputField value="{!c.Answer__c}">
                        <apex:actionSupport event="onchange" 
                                            rerender="idPageBlock1"
                                            status="idStatus"/>
                        </apex:inputField>
                        <apex:actionStatus startText="processing..." id="idStatus"/>
                    </apex:outputPanel>  
                </apex:column>

                <apex:column headerValue="Comment">
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Comments__c}" />
                </apex:column>

                <apex:column headerValue="Issue">
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Issue__c}" rendered="{!c.Answer__c == ''}"/>
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Issue__c}" rendered="{!c.Answer__c == 'Yes'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_NO_Issue__c}" rendered="{!c.Answer__c == 'No'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_A_Issue__c}" rendered="{!c.Answer__c == 'In-Part A'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_B_Issue__c}" rendered="{!c.Answer__c == 'In-Part B'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_C_Issue__c}" rendered="{!c.Answer__c == 'In-Part C'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Issue__c}" rendered="{!c.Answer__c == 'N/A'}" />                 
                </apex:column>    
                                
                <apex:column headerValue="Action">
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Action__c}" rendered="{!c.Answer__c == ''}" />               
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Action__c}" rendered="{!c.Answer__c == 'Yes'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_NO_Action__c}" rendered="{!c.Answer__c == 'No'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_A_Action__c}" rendered="{!c.Answer__c == 'In-Part A'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_B_Action__c}" rendered="{!c.Answer__c == 'In-Part B'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_C_Action__c}" rendered="{!c.Answer__c == 'In-Part C'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Action__c}" rendered="{!c.Answer__c == 'N/A'}" />
                </apex:column>

            </apex:pageBlockTable>

        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 


 

 

 

 

SidzSidz

Hi mtan,

In the code you specified  you are using an standard controller and extension and in the extension

you must be querying the checklist items and mapping it to a list ChecklistItems

which is being displayed in the vf page

 

instead of querying the checklistitems you can use a attribute called recordsetVar in apex:page

it will contain all the records of the checklist object for you to loop through

this will save a backend operation and the performance can be increased.

 

hope it helps,

sidz

mtanmtan

Hi Sidz,

 

Thanks for the quick reply. I checked the recordSetVar option you recommended and reading through the VisualForce documentation it seems that it is already being used in the code.

 

Below refers to that part of the code:

 

 <apex:pageBlockTable value="{!ChecklistItems}" var="c" id="idPageBlockTable1">

 

When using the visual page, I noticed that it is taking time when the text "processing..." is displayed but I am not sure how to optimize it.

 

                <apex:column headerValue="Answer">
                    <apex:outputPanel id="idAnswerOutputPanel" >
                        <apex:inputField value="{!c.Answer__c}">
                        <apex:actionSupport event="onchange" 
                                            rerender="idPageBlock1"
                                            status="idStatus"/>
                        </apex:inputField>
                        <apex:actionStatus startText="processing..." id="idStatus"/>
                    </apex:outputPanel>  
                </apex:column>

 Any idea? That will be much appreciated. Thanks.

 

 

 

SidzSidz

i was referring to using it this way

<apex:page standardController="Check_list__c" recorSetVar="ChecklistItems">

<apex:pageBlockTable value="{!ChecklistItems}" var="c" id="idPageBlockTable1">

</apex:page>

SantoshiSantoshi

Hi,

the var which you are using in your code is different from recordsetvar. The recordsetvar is attribute of <apex:page> and we generally use it when processing bulk of records,you can get in help.  One more thing instead of rerendering the whole pageblock in your action support only rerender the pageblock table this may help.

aballardaballard

If you are seeing the "processing..." status message for a long time you should also look into what apex code is being executed during the action that is being processed.  

mtanmtan

Hi Sidz,

 

Thanks for the clarification. I was able to modify the code in our sandbox and tried testing the load time again. It doesn't seem to do much difference in terms of the loading time.

 

I've read somewhere that it is possible to rerender only the row that has been modified instead of the whole page/block but am struggling to implement it in the my code. I tried to look for sample codes but unfortunately can't find any. Would you be able to help?

 

Thanks, again.

 

SidzSidz

hi mtan,

can you paste your apex code so we can see theif there is any way.

MaidyMaidy

Hi Sidz,

 

Here are the codes:

 

Visualforce Page

 

<apex:page standardController="Checklist_Item__c" extensions="CollectChecklistItemsExtension" recordSetvar="ChecklistItems" sidebar="false">
    <apex:form > 
        <apex:pageBlock title="Edit Checklist Item Data" id="idPageBlock" mode="edit">
            <apex:pageMessages /> 
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockTable value="{!ChecklistItems}" var="c" id="idPageBlockTable">
    
                <apex:column value="{!c.Id}" rendered="false" />
                
                <apex:column value="{!c.Question_Category__c}" headerValue="Category" />                
                
                <apex:column value="{!c.Question__c}" /> 
                
                <apex:column headerValue="Answer">
                    <apex:outputPanel id="idAnswerOutputPanel" >
                        <apex:inputField value="{!c.Answer__c}">
                        <apex:actionSupport event="onchange" rerender="idPageBlock" status="idStatus"/>
                        </apex:inputField>
                        <apex:actionStatus startText="processing..." id="idStatus"/>
                    </apex:outputPanel>  
                </apex:column>

                <apex:column headerValue="Comment">
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Comments__c}" />
                </apex:column>

                <apex:column headerValue="Issue">
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Issue__c}" rendered="{!c.Answer__c == ''}"/>
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Issue__c}" rendered="{!c.Answer__c == 'Yes'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_NO_Issue__c}" rendered="{!c.Answer__c == 'No'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_A_Issue__c}" rendered="{!c.Answer__c == 'In-Part A'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_B_Issue__c}" rendered="{!c.Answer__c == 'In-Part B'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_C_Issue__c}" rendered="{!c.Answer__c == 'In-Part C'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Issue__c}" rendered="{!c.Answer__c == 'N/A'}" />                 
                </apex:column>    
                                
                <apex:column headerValue="Action">
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Action__c}" rendered="{!c.Answer__c == ''}" />               
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Action__c}" rendered="{!c.Answer__c == 'Yes'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_NO_Action__c}" rendered="{!c.Answer__c == 'No'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_A_Action__c}" rendered="{!c.Answer__c == 'In-Part A'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_B_Action__c}" rendered="{!c.Answer__c == 'In-Part B'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Default_In_Part_C_Action__c}" rendered="{!c.Answer__c == 'In-Part C'}" />
                    <apex:InputTextArea rows="10" cols="40" value="{!c.Action__c}" rendered="{!c.Answer__c == 'N/A'}" />
                </apex:column>

            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Apex Class Extension

public class CollectChecklistItemsExtension {

    public List<Checklist_Item__c> chklstitm;
    public CollectChecklistItemsExtension(ApexPages.StandardSetController controller) 
    {
      chklstitm = (List<Checklist_Item__c>) 
           [select id, Question_Category__c, Question__c, Answer__c, Comments__c, Action__c, Issue__c,
                   Default_In_Part_A_Action__c, Default_In_Part_A_Issue__c,
                   Default_In_Part_B_Action__c, Default_In_Part_B_Issue__c,
                   Default_In_Part_C_Action__c, Default_In_Part_C_Issue__c,
                   Default_NO_Action__c, Default_NO_Issue__c
            from Checklist_Item__c 
            where Checklist__c = :ApexPages.currentPage().getParameters().get('id')];
    }    
    public List<Checklist_Item__c> getChecklistItems() 
    {
         return chklstitm;
    }
    public PageReference save() 
    {
      update chklstitm;
      PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));        
      home.setRedirect(true);        
      return home;
    }
}

 

Update Checklist_Item__c Trigger

trigger UpdateDefaultText on Checklist_Item__c (before update, before insert){   

    for (Checklist_Item__c c : Trigger.new){
    
        // Create maps to compare old and new values
        Checklist_Item__c oldChklst = Trigger.oldMap.get(c.Id);
        Checklist_Item__c newChklst = Trigger.newMap.get(c.Id);       
    
        // Retrieve the old and new Answers
        String oldAnswer = oldChklst.Answer__c;
        String newAnswer = newChklst.Answer__c;
        
        // Update fields where answer has been changed
        if ((c.Answer__c != null) && (oldChklst.Answer__c != newChklst.Answer__c)){

            if (c.Answer__c.equals('In-Part A'))
            {
                c.Penalty_Score__c  = c.In_Part_A_Score__c;
                c.Action__c         = c.Default_In_Part_A_Action__c;
                c.Issue__c          = c.Default_In_Part_A_Issue__c;
            } 
            else if(c.Answer__c.equals('In-Part B'))
            {
                c.Penalty_Score__c  = c.In_Part_B_Score__c;
                c.Action__c         = c.Default_In_Part_B_Action__c;
                c.Issue__c          = c.Default_In_Part_B_Issue__c; 
            }
            else if(c.Answer__c.equals('In-Part C'))
            {
                c.Penalty_Score__c  = c.In_Part_C_Score__c;
                c.Action__c         = c.Default_In_Part_C_Action__c;
                c.Issue__c          = c.Default_In_Part_C_Issue__c;
            }
            else if(c.Answer__c.equals('No'))
            {
                c.Penalty_Score__c  = c.NO_Score__c;
                c.Action__c         = c.Default_NO_Action__c;
                c.Issue__c          = c.Default_NO_Issue__c;
            }                      
            else
            {    
                c.Penalty_Score__c  = 0;
            }             
        }
    }
}

 

Thanks, again.

 

 

MaidyMaidy

Hi Sidz,

 

Sorry to bother you but would just like to check if you had the chance to look into the codes I've sent through and if you have any recommendations as to how else the loading time may be improved.

 

Many thanks.