You need to sign in to do that
Don't have an account?
Anish Singh
My visual force page taking longer time to render
My visual force page taking longer time to render or load the page if the records are more than 100. I am providing you with my VF page & controller class.
Please suggest do i have to use transient in order to overcome this.
---------------------------------------------------------------------------------------------
VF page: (for task):
<apex:pageBlock title="My Tasks" id="pb1" > <div class="slds-col--padded slds-size--1-of-1 myTaskList"> <apex:selectList value="{!selectedFilterTaskString}" styleClass="selectfld" size="1" onchange="filterTasks('{!JSENCODE(selectedFilterTaskString)}')"> <apex:selectOptions id="selectedOpt" value="{!filterTaskList}"/> <apex:actionFunction action="{!fetchRelatedTasks}" name="filterTasks" rerender="taskTabPanel,dataTableInitialization" status="spinnerStatus"> </apex:actionFunction> </apex:selectList> </div> <!-- List to iterate to be shown on page --> <apex:outputPanel id="taskTabPanel"> <div Class="slds-table slds-table--bordered"> <apex:pageBlockTable value="{!taskList}" var="task" styleClass="_dataTable">
____________________________________________________
Controller:
public with sharing class EngTaskListPageCtrl {
public List<Task> taskList {get;set;} //list of tasks to be shown on page
public List<SelectOption> filterTaskList {get;set;} //option list to be displayed in filter
public String selectedFilterTaskString { get; set;} //selected option from option list options
public Set<ID> BHGroupUserIDs{get; set;}//List of user ids belongs to Behavior Health User Group
private List<String> taskStatusList;
public void fetchRelatedTasks(){
try{
String whereClause = ''; //creates where clause based on various criteria to be passed in Database query
Id currentUser = UserInfo.getUserId(); //get current logged in user Id
if (selectedFilterTaskString != 'MASCO BH'){
if(selectedFilterTaskString == 'All Open (next 30 days)'){
whereClause = 'WHERE (ActivityDate <= NEXT_N_DAYS:30) and';
}
else if(selectedFilterTaskString == 'Overdue'){
whereClause = 'WHERE ActivityDate <= YESTERDAY and';
}
else if(selectedFilterTaskString == 'Today'){
whereClause = 'WHERE ActivityDate = TODAY and';
}
else if(selectedFilterTaskString == 'Today + Overdue'){
whereClause = 'WHERE ActivityDate <= TODAY and';
}
else if (selectedFilterTaskString == 'Tomorrow'){
whereClause = 'WHERE ActivityDate = TOMORROW and';
}
else if (selectedFilterTaskString == 'Next 7 Days'){
whereClause = 'WHERE ActivityDate = NEXT_WEEK and';
}
else if (selectedFilterTaskString == 'Next 7 Days + Overdue'){
whereClause = 'WHERE (ActivityDate < TODAY OR ActivityDate = NEXT_WEEK) and';
}
else if (selectedFilterTaskString == 'This Month'){
whereClause = 'WHERE ActivityDate = THIS_MONTH and';
}
//get the tasks based on criteria selected from page
//DE109368-On Call Communication - Empty Task
taskList = Database.query('SELECT id,Account.Name,Priority ,Status,WhatID, WhoID,Who.name,ActivityDate,Subject, What.Name,RecordType.Name, Description, '+
'RelatedTo__c,RelatedTo__r.Name,Facility__c,Facility__r.Name,Clinical_Note_Subject_Type__c,type,CreatedDate FROM Task '+whereClause+' OwnerId =:currentUser '+
'AND Status IN :taskStatusList LIMIT 1000');
}
//US1115209: Create a Post hospitalization queue for MASCO/OH - Devashri
else if (selectedFilterTaskString == 'MASCO BH' && BHGroupUserIDs.contains(currentUser)){
taskList.clear();
List<Engagement__c> mascoEngList = Database.query('SELECT id FROM Engagement__c WHERE Market__c LIKE \'%Masco%\'');
List<String> engIdList = new List<String>();
for (Engagement__c eng : mascoEngList) {
engIdList.add(eng.Id);
}
taskList = Database.query('SELECT id,Account.Name,Priority ,Status,WhatID, WhoID,Who.name,ActivityDate,Subject, What.Name,RecordType.Name, Description, '+
'RelatedTo__c,RelatedTo__r.Name,Facility__c,Facility__r.Name,Clinical_Note_Subject_Type__c,type,CreatedDate FROM Task WHERE WhatId IN :engIdList LIMIT 1000');
/*List<Task>taskToShows = new List<Task>();
for (Task currentTask : taskList) {
if(String.isNotEmpty(currentTask.WhatID) && String.valueOf(currentTask.WhatID).startsWith('a1Y')
&& engIdList.contains(currentTask.WhatID)){
if(Date.Today().daysBetween(currentTask.ActivityDate) <=0){
taskToShows.add(currentTask);
}
}
}
taskList.clear();
taskList.addAll(taskToShows);*/
}
else{
taskList.clear();
}
}
catch(Exception ex){
IsErrorOnLoad = true;
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
CustomLogger.log(ex,'',ApexPages.currentPage(),LoggingLevel.INFO);
}
}
_______________________________________________________
Thanks,
Anish Singh
Please suggest do i have to use transient in order to overcome this.
---------------------------------------------------------------------------------------------
VF page: (for task):
<apex:pageBlock title="My Tasks" id="pb1" > <div class="slds-col--padded slds-size--1-of-1 myTaskList"> <apex:selectList value="{!selectedFilterTaskString}" styleClass="selectfld" size="1" onchange="filterTasks('{!JSENCODE(selectedFilterTaskString)}')"> <apex:selectOptions id="selectedOpt" value="{!filterTaskList}"/> <apex:actionFunction action="{!fetchRelatedTasks}" name="filterTasks" rerender="taskTabPanel,dataTableInitialization" status="spinnerStatus"> </apex:actionFunction> </apex:selectList> </div> <!-- List to iterate to be shown on page --> <apex:outputPanel id="taskTabPanel"> <div Class="slds-table slds-table--bordered"> <apex:pageBlockTable value="{!taskList}" var="task" styleClass="_dataTable">
____________________________________________________
Controller:
public with sharing class EngTaskListPageCtrl {
public List<Task> taskList {get;set;} //list of tasks to be shown on page
public List<SelectOption> filterTaskList {get;set;} //option list to be displayed in filter
public String selectedFilterTaskString { get; set;} //selected option from option list options
public Set<ID> BHGroupUserIDs{get; set;}//List of user ids belongs to Behavior Health User Group
private List<String> taskStatusList;
public void fetchRelatedTasks(){
try{
String whereClause = ''; //creates where clause based on various criteria to be passed in Database query
Id currentUser = UserInfo.getUserId(); //get current logged in user Id
if (selectedFilterTaskString != 'MASCO BH'){
if(selectedFilterTaskString == 'All Open (next 30 days)'){
whereClause = 'WHERE (ActivityDate <= NEXT_N_DAYS:30) and';
}
else if(selectedFilterTaskString == 'Overdue'){
whereClause = 'WHERE ActivityDate <= YESTERDAY and';
}
else if(selectedFilterTaskString == 'Today'){
whereClause = 'WHERE ActivityDate = TODAY and';
}
else if(selectedFilterTaskString == 'Today + Overdue'){
whereClause = 'WHERE ActivityDate <= TODAY and';
}
else if (selectedFilterTaskString == 'Tomorrow'){
whereClause = 'WHERE ActivityDate = TOMORROW and';
}
else if (selectedFilterTaskString == 'Next 7 Days'){
whereClause = 'WHERE ActivityDate = NEXT_WEEK and';
}
else if (selectedFilterTaskString == 'Next 7 Days + Overdue'){
whereClause = 'WHERE (ActivityDate < TODAY OR ActivityDate = NEXT_WEEK) and';
}
else if (selectedFilterTaskString == 'This Month'){
whereClause = 'WHERE ActivityDate = THIS_MONTH and';
}
//get the tasks based on criteria selected from page
//DE109368-On Call Communication - Empty Task
taskList = Database.query('SELECT id,Account.Name,Priority ,Status,WhatID, WhoID,Who.name,ActivityDate,Subject, What.Name,RecordType.Name, Description, '+
'RelatedTo__c,RelatedTo__r.Name,Facility__c,Facility__r.Name,Clinical_Note_Subject_Type__c,type,CreatedDate FROM Task '+whereClause+' OwnerId =:currentUser '+
'AND Status IN :taskStatusList LIMIT 1000');
}
//US1115209: Create a Post hospitalization queue for MASCO/OH - Devashri
else if (selectedFilterTaskString == 'MASCO BH' && BHGroupUserIDs.contains(currentUser)){
taskList.clear();
List<Engagement__c> mascoEngList = Database.query('SELECT id FROM Engagement__c WHERE Market__c LIKE \'%Masco%\'');
List<String> engIdList = new List<String>();
for (Engagement__c eng : mascoEngList) {
engIdList.add(eng.Id);
}
taskList = Database.query('SELECT id,Account.Name,Priority ,Status,WhatID, WhoID,Who.name,ActivityDate,Subject, What.Name,RecordType.Name, Description, '+
'RelatedTo__c,RelatedTo__r.Name,Facility__c,Facility__r.Name,Clinical_Note_Subject_Type__c,type,CreatedDate FROM Task WHERE WhatId IN :engIdList LIMIT 1000');
/*List<Task>taskToShows = new List<Task>();
for (Task currentTask : taskList) {
if(String.isNotEmpty(currentTask.WhatID) && String.valueOf(currentTask.WhatID).startsWith('a1Y')
&& engIdList.contains(currentTask.WhatID)){
if(Date.Today().daysBetween(currentTask.ActivityDate) <=0){
taskToShows.add(currentTask);
}
}
}
taskList.clear();
taskList.addAll(taskToShows);*/
}
else{
taskList.clear();
}
}
catch(Exception ex){
IsErrorOnLoad = true;
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,ex.getMessage()));
CustomLogger.log(ex,'',ApexPages.currentPage(),LoggingLevel.INFO);
}
}
_______________________________________________________
Thanks,
Anish Singh
Top 5 Tips for Improving Visualforce Pages:
1. Reduce or eliminate the view state.
2. Evaluate SOQL for Efficiency.
3. Reduce the use of Action tags.
4. Take Advantage of StandardSetControllers when dealing with lists of data.
5. Incorporate Best Practices with all JavaScript, CSS, and Images.
Check these blog for best practices to Improving Visualforce Page Performance:
https://saramorgan.net/2014/07/14/top-5-tips-for-improving-visualforce-pages/
https://developer.salesforce.com/blogs/developer-relations/2015/01/best-practices-improving-visualforce-page-performance.html
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Thanks for your information, I already tried using these tips, but wanted to just consult whether my code is correct or not, or if using trasient will it resolve my issue.
thanks,
Anish