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
Deepu161Deepu161 

need to display list based on the desc order of dates

SELECT  Id,
                                                Name,
                                                Project__c,
                                                Employee__c,
                                                Client_Pay__c,
                                                Client_Pay_Per_Day__c,
                                                Hours__c,
                                                Date_Of_Service__c,
                                                Invoice__c
                                        FROM    Timecard__c
                                                
                                        WHERE   Employee__c IN  :empids 
                                            AND project__c = :objInvoices.Project__c
                                            AND Date_Of_Service__c >= :objInvoices.Service_Term_From__c
                                            AND Date_Of_Service__c  <= :objInvoices.Service_Term_To__c
                                           order by  Date_Of_Service__c desc ];

 
Anil KamisettyAnil Kamisetty
What is the Issue here ? Isn't it sorted on the Date of Service ?

If so, you can do the following.

1. Read the Results into list
2. Load them into a Map (with Date as the Key)
3. Sort the values in the Map
4. Covnert the map values into List (used Values method)

Note : if there are more than one records for the same date, try to come up with some logic to build the key such that all records can be loaded into the Map.
hai.huanghai.huang
Check the doc: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_orderby.htm (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_orderby.htm" target="_blank)
The following limitations apply to data types when using ORDER BY:
These data types are not supported: multi-select picklist, rich text area, long text area, encrypted (if enabled), and data category group reference (if Salesforce Knowledge is enabled).
All other data types are supported, with the following caveats:
Corporate currency always sorts using corporate currency value, if available.
phone data does not include any special formatting when sorting, for example, non-numeric characters such as dash or parentheses are included in the sorting.
picklist sorting is defined by the picklist sort determined during setup.
As the sql will return a list, may be you can try sort(). Related doc:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_list_sorting_sobject.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_list_sorting_sobject.htm" target="_blank)

Hope it will help you.

Best,
Huang https://randsfdc.blogspot.com