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

Need help with custom sort options

I am new to apex, and have little java experience.

I am trying to setup a custom sort method for a custom object support__C
I would like to be able to first sort by a custom field titled Closed__c (this field allows a default value of checked or unchecked in a check box) more specifically... I would like to have the custom fields default value unchecked be listed first and checked to be below.

Then I would like to add a method that sorts both checked and unchecked lists by the date created.

The idea: if a topic is unchecked it is not closed, I want it at the top, but I also then want to sort all unchecked by date created.
then repeat the same for default value checked which would mean closed.
Hi Zingo,

You can use order by in SOQL, first you have to add Closed__c and then CreatedDate then the value will come defult in order.

If you have given only very top level requiremnt. If you need more help please let me know.

Regards | Atul
Can you give an example, I have not been able to get this working any way I have tried. Maybe I should use: fieldOrderByList?
By the way the current sort options for the object support are: Recently Created, Recently Modified, and Recently Viewed... I have put in: Search Filter Fields Closed, Created By, Last Modified Date but do not see where I can search by these.
Hi Zingo,
Do you need to display the sorted result based on all those criteria or you want to sort after the result is shown?
I do not need to sort by all those critreia, if I could even just sort by closed (checked or unchecked) this would be a big help. I will try the compareTo method
Hi Zingo,

You could do your query like this:

 [SELECT id, nam, closed__c from support__c where closed__c != null order by closed__c];
//you can put asc at the end then it will show you the closed__c = false first and if you do it desc then it will show you the closed__c = true first;
[SELECT id, nam, closed__c from support__c where closed__c != null order by closed__c asc/desc];

Let me know if that is what you wanted.

I think this will work to my needs, thanks!