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
Cool_DevloperCool_Devloper 

Ordering a List of Custom Object Records

Hello Friends,

I have a query regarding ordering of a custom List having Custom Object records!

In this scenario, I cannot use Order-By as I am not populating this list directly from a SOQL query. Also, I am sure, we can write custom logic for ordering a custom list, but I was just thiking if I can avoid writing custom code.

But the thing, I am not sure is, how a "DataList" component works. I read the docs which say that it can be ordered or un-ordered, but I am unable to follow it completely considering my scenario.

What if, my list is having 5 fields per custom obejct record, then how does the datalist arrange the data based on a specific field, say Name?

Can someone please clarify this? Also, what is the best approach/solution in such a case?

Many Thanks,

Cool_D

Message Edited by Cool_Devloper on 12-01-2009 12:46 AM
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I believe that the ordered/unordered here refers to the type of HTML list tags that will be generated.  An ordered list is enclosed in <ol> tags and will add cardinality, so the list will appear as :

 

   1. Item 1

   2. Item 2

 

 

etc

 

While an unordered list will be enclosed in <ul> tags and display as:

 

o Item 1

o Item2

 
It will still be up to you to provide ordering prior to returning the backing list.
 
I reckon you'll end up having to write some code to achieve this.  I've done this before by storing my non-sObject objects in a map keyed on the sortable field, then storing the values for the field I want to sort on in a primitive List and using the built-in sort method.  That gives me the fields in the correct order, which allows me to retrieve the objects in the correct order from the map.  Of course, this will only work if your sortable field is unique.  I recall I had to unique mine by adding an index (that was never used outside of the sorting) to the object and concatenating this with the sortable field. 
 

 [edited as submitting from chrome removed the vital list formatting!]

Message Edited by bob_buzzard on 12-01-2009 02:07 AM

All Answers

bob_buzzardbob_buzzard

I believe that the ordered/unordered here refers to the type of HTML list tags that will be generated.  An ordered list is enclosed in <ol> tags and will add cardinality, so the list will appear as :

 

   1. Item 1

   2. Item 2

 

 

etc

 

While an unordered list will be enclosed in <ul> tags and display as:

 

o Item 1

o Item2

 
It will still be up to you to provide ordering prior to returning the backing list.
 
I reckon you'll end up having to write some code to achieve this.  I've done this before by storing my non-sObject objects in a map keyed on the sortable field, then storing the values for the field I want to sort on in a primitive List and using the built-in sort method.  That gives me the fields in the correct order, which allows me to retrieve the objects in the correct order from the map.  Of course, this will only work if your sortable field is unique.  I recall I had to unique mine by adding an index (that was never used outside of the sorting) to the object and concatenating this with the sortable field. 
 

 [edited as submitting from chrome removed the vital list formatting!]

Message Edited by bob_buzzard on 12-01-2009 02:07 AM
This was selected as the best answer
Cool_DevloperCool_Devloper

Thanks so very much Bob for the elaborate and informative answer;)

That surely, clarifies my issues!

I will try the custom logic you have mentioned and see, if I can do something similar. It does'nt seem to be too complex at the face of it :)

Thanks Again!!

Cool_D