+ Start a Discussion

SOQL Default Ordering and Retrieval

I had a couple of questions around the ordering of object content when they are inserted into Salesforce. Specifically, my ask would be a thorough explanation of how content is ordered and retrieved. 

After searching around for awhile it sounds like Salesforce gives no guarantees on ordering of results (specifically noted in the documentation online) as well as other sources online. I'm hoping to pose my questions in respect to their online counterparts below.

a) Here (https://developer.salesforce.com/forums/?id=906F000000092srIAA) for example indicates that ordering by CreatedDate after the insertion of two accounts one after the other will give inaccurate results but that is to be expected. More specifically sfdcfox's later on indicates that you can order by Id instead and that they are always in ascending order.
b) Here (http://salesforce.stackexchange.com/questions/7667/soql-result-ordering-in-the-absence-of-an-order-by-clause)indicates that if the Order By clause is missing then a variety of factors that may affect it which further is corroborated with my third source
c) The Salesforce Developer's guide also indicates (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select.htm)that there is no guarantee for order unless you use the Order By clause.

So my questions then follow:
1) If there is no gurantee for order then how can we guarantee that Id is ALWAYS created in ascending order. Who or what is more accurate in this case? And is this a reliable way to order?
2) The Salesforce Developer's guide (a) is ambiguous just stating that there is no guarantee and likewise the second point (b) indicates that there are a variety of factors that influence this. Does anyone know specifically what the cases and conditions would be?
3) What is the most basic case as well as the 80% satisfiable cases for a default behaviour? If I run multiple inserts on a default object will it be inserted in that order or garble it. And when I retrieve that data via SELECT Id, Name FROM [OBJECT] will it give it back in the order that it had previously inserted with (garbled or in order).

Hi PeterN, 

I am also curious and researching over the same cases. 
1. We can also no guarantee that i would  be in ascending order always it is a matter of actual comitting data in to database. 
2. It might be related to their alogrithm running behind the screen which may depends on what data goes and committed actually.
3. No It is not alwasy happen as I have tried to inserted 1000 records through a list and when I retrived the list ids were not in that order in which I have added those in the list to be inserted It might also be dependent resource/space availability mechanism.

Sandeep Singhal
My unit test failed in one of sandboxes, due to different order retrieved with 2 identical Select statements. (No SeeAllData set to true, API version 28.0).