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
NervosaNervosa 

Sorting custom object in a pageBlockTable

Greetings everyone!

Surfing over the Internet trying to find information about sorting on a VF pages i've found this - http://salesforcesource.blogspot.com/2008/11/adding-sorting-capability-to.html

and it was a desirable discovery BUT!! - it is ALMOST what i was searching for. The problem is that in my case there is a custom object. And that tutorial concerns only sObjects. Everything in it is applicable for my Item__c object except this part:

 

   public PageReference ViewData() {
       //build the full sort expression
       string sortFullExp = sortExpression  + ' ' + sortDirection;
      
       //query the database based on the sort expression
       accounts = Database.query('Select id, Name, BillingCity, BillingCountry, Phone from Account order by ' + sortFullExp + ' limit 1000');
       return null;
   }

 I don't see ways how can i do that with custom object. Please help me.

 

Thanks in advance.

logontokartiklogontokartik

Try building the query for your custom object instead of Accounts.

 

List<YourCustomObject> records = Database.query('Select <your custom object fields> from <yourcustomobject> order by '  + sortFullExp + ' limit 1000');