Contents
How do I sort a SOQL query?
ORDER BY
- [ORDER BY fieldOrderByList {ASC|DESC} [NULLS {FIRST|LAST}] ]
- SELECT Name FROM Account ORDER BY Name DESC NULLS LAST.
- SELECT Name FROM Account WHERE industry = ‘media’ ORDER BY BillingPostalCode ASC NULLS LAST LIMIT 125.
How do I query all columns in SOQL?
You can now include any of these in the field list:
- FIELDS(ALL) —to select all the fields of an object.
- FIELDS(CUSTOM) —to select all the custom fields of an object.
- FIELDS(STANDARD) —to select all the standard fields of an object.
What is the default sorting in SOQL?
ascending
Default order is ascending. Orders null records at the beginning ( NULLS FIRST ) or end ( NULLS LAST ) of the results. By default, null values are sorted first.
When to use order by in SOSL query?
If records are null, you can use ORDER BY to display the empty records first or last. You can use ORDER BY in a SELECT statement to control the order of the query results.
What happens when a sobject field is not selected in a SOSL query?
SOQL and SOSL queries only return data for sObject fields that are selected in the original query. If you try to access a field that was not selected in the SOQL or SOSL query (other than ID), you receive a runtime error, even if the field contains a value in the database.
How does the Order work in soql for English locales?
For English locales, SOQL uses the UTF-8 values of the uppercase character to create a sort order. In other words, sorting for English locales is case insensitive. For non-English locales, SOQL uses a pre-defined order that is natural for the locale specified.
How are null values sorted in Salesforce order by?
By default, null values are sorted first. For example, the following query returns a query result with Account records in alphabetical order by first name, sorted in descending order, with accounts that have null names appearing last: ORDER BY is compatible with relationship query syntax.