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
IamSRNIamSRN 

SOQL FOR Loop with ORDER BY clause gives un-ordered list

When SOQL For loops used with ORDER by clause, list gives un-ordered list. We had to store the query in a local variable and loop through it to solve this issue. Any ides why this is happening?
Alain CabonAlain Cabon
Is it a picklist?

[ORDER BY ***fieldOrderByList*** {ASC|DESC} [NULLS {FIRST|LAST}] ]

1) 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).

2) All other data types are supported, with the following caveats:
2.1) Corporate currency always sorts using corporate currency value, if available.
2.2) 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.
2.3) picklist sorting is defined by the picklist sort determined during setup.

3) The following factors affect results returned with ORDER BY:
3.1) Sorting is case insensitive.
3.2) Sort order is determined by current user locale.

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_orderby.htm

Alain