Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

In the absence of an Order By clause in a SOQL query, what order will Salesforce return results in?

Clearly if ordering is important then Order By should be specified, but I recently encountered a question about what the order would be if it was undefined.

My initial thoughts were Salesforce would return them in whatever order suited them. Much like SQL. For simple queries this would typically line up with the creation date descending and the Id ascending. For more complex queries it would depend on the joins being performed.

share|improve this question

2 Answers 2

up vote 8 down vote accepted

If you don't specify a where clause, the order of the returned rows is undefined, and a whole host of things can affect it including which columns you select,what your where clause is, if its a standard or custom object, if it has to do sharing checks, if it has to generate an API cursor and so on.

share|improve this answer

According to the SOQL / SOSL Reference - SOQL SELECT Syntax (at the bottom of the page):

Ordered Results—There is no guarantee of the order of results unless you use an ORDER BY clause in a query.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.