Does Database.getQueryLocator respect order by clause while running a batch? I am using following code

Database.getQueryLocator([select id,name from account order by industry asc])

Will this batch first process records where industry is null?

2 Answers 2


I believe the answer is yes it does, and yes it will.

This is the results from the query in Dev console:

enter image description here

Which I appreciate doesn't answer your question, but I know that Database.getQueryLocator does certainly appear to respect sort order from having used it in the past in other projects - e.g. for sorting Opportunity Line Items by AccountID and Quantity.


SOQL returns null values first per the salesforce documentation, unless you specify NULLS LATST in your query. To avoid confusion you can chose to expressly say NULLS FIRST if that is what you want.

Regardless of nulls first or nulls last they will be included unless they are expressly excluded by your WHERE clause.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .