You need to sign in to do that
Don't have an account?
yeshab
Order by clause ignored in the apex class code
I am doing a simple query on custom object like below:
SELECT Widget__c.Name, Id, orderid__c, (SELECT Model__c.Name FROM Widget__c.Models__r) FROM Widget__c order by orderid__c
orderid__c is a numeric field, used to sort.
it works fine in the developer console query editor, but doesn't appear in ordered form in the code.
any help would be great!!!
Thanks,
SELECT Widget__c.Name, Id, orderid__c, (SELECT Model__c.Name FROM Widget__c.Models__r) FROM Widget__c order by orderid__c
orderid__c is a numeric field, used to sort.
it works fine in the developer console query editor, but doesn't appear in ordered form in the code.
any help would be great!!!
Thanks,
1) Do you have null OrderId__c values? If so, try appending "NULLS FIRST" or "NULLS LAST" to your ORDER BY statement, depending on your requirement.
2) Are you feeding the query values into a Map at some point in your Apex class? Maps are unordered, so if you use maps to pass your data around, then the data will become out of order. To fix this you'll need to use lists instead of maps.
All Answers
Run this in the Workbench and cjeck it once. However, i am not sure how your are confirming that the records are not in order.
Regards
Pramod
i am displaying the result in the visualforce page.
1) Do you have null OrderId__c values? If so, try appending "NULLS FIRST" or "NULLS LAST" to your ORDER BY statement, depending on your requirement.
2) Are you feeding the query values into a Map at some point in your Apex class? Maps are unordered, so if you use maps to pass your data around, then the data will become out of order. To fix this you'll need to use lists instead of maps.