SOQL ORDER BY Clause | ASC, DESC

SOQL ORDER BY Clause : In our previous salesforce tutorial we have learned about SOQL logical operators in salesforce. In this Salesforce Training tutorial we are going to learn about ORDER BY clauses called “ASC”. and “DESC”.

What is SOQL ORDER BY Clause ?

ORDER BY Clause is used to retrieve the data in ¬†“Ascending” or “Descending” order by the condition given in SOQL Statement.

In salesforce ORDER BY clause are two types. They are

  1. ASC.
  2. DESC.

Here ASC means ascending and DESC means descending order. In SOQL by default the data will be retrieved in ascending order only.

SOQL ORDER BY Clause ASC

  • SELECT name, Amount FROM opportunity ORDER BY name ASC.

SOQL ORDER BY Clause | ASC, DESC

Here we have used ORDER BY Clause called ASC. From above SOQL statement name and Amount values will be retrieved from Opportunity and records will be arranged in Ascending order.

SOQL ORDER BY Clause DESC.

  • SELECT name, Amount FROM Opportunity ORDER BY name DESC.

SOQL ORDER BY Clause | ASC, DESC

Here we have used SOQL ORDER BY clause called “DESC”. From above SOQL ¬†statement name and Amount values will be retrieved from opportunity in descending order.

Comments on this entry are closed.