I'm trying to sort a list of tasks by their due date in ascending order. I've looked in a couple of forums and none are what I exactly need. I'm sure this should be relatively easy but haven't found the way.

list <task> Tareas_abiertas  = [SELECT Id from Task where OwnerId =:usuario.id AND status='Open'];

My query is simple I just need to order it depending on due date. Help?


Try this -

list <task> Tareas_abiertas  = [SELECT Id from Task where OwnerId =:usuario.id AND status='Open' Order By ActivityDate];

And from this Salesforce help article you can see that the API name of Due Date is ActivityDate.

Also as suggested by @IllusiveBrian, here is the documentation on SOQL Order By - https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_orderby.htm#


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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