+ Start a Discussion
SFDC coderSFDC coder 

How to improve a list's performance?

hi all,

i have a functionality wherein the pageblock table data is sorted when an appropriate column header is clicked.
Even though this functionality seems to be working fine,
it takes a lot of time to display the result on the VF page

Can anyone help me to make the records display faster on VF page?

below is my method i.e invoked whenever a column header is clicked

public PageReference doSorting()
        sortOrder= sortOrder.equals('asc') ? 'desc' : 'asc';
        System.debug('***** sort order is'+sortOrder);
        List<Product__c> prodlst=runQuery();
            for(Product__c pnew2: prodlst)
                        OrderWrapper ow2=new OrderWrapper();
                        ow2.oliItem=new Order_Line_Item__c();
        return null;
    public  List<Product__c> runQuery()
         sortedProds=Database.Query('select id,name,Product_Brand__c,Product_Category__c from         Product__c Order by '+sortParam+' '+sortOrder);
         return sortedProds;

James LoghryJames Loghry
There's a little code cleanup you could do, but nothing that would matter much performance wise.

Looks like the real bottleneck is your query at line 24.  You have no filters on your query so it's going to do a full table scan and return all results of your Product__c object.  If the query is unbearably slow, you'll want to look into indexing and other forms of query optimization.  Perhaps this will help: http://help.salesforce.com/help/pdfs/en/salesforce_query_search_optimization_developer_cheatsheet.pdf
The only way you are going to see real improvement I think is to carry out the sort client side.  That would stop the round trip to the server and the requery from the database.

Something like the jQuery table sorter should be able to help http://tablesorter.com/docs/.