Book Image

Getting Started with SOQL

By : Magulan D
Book Image

Getting Started with SOQL

By: Magulan D

Overview of this book

<p>This practical guide will tell you everything you need to know about SOQL statements. You will learn the optimum way to write complex SOQL statements with this easy-to-understand guide. Beginning with basic SOQL statements, you will progress quickly onto more advanced statements, such as how to filter multiselect picklist values to escape sequences.</p> <p>This book will teach you how to sort records with more than one field, sorting with more than one field–one in ascending order and another field in descending order—and sorting null records in the first or in the last. You will learn about all the features provided while you are writing SOQL statements. This book will make you a SOQL expert by teaching you how to write SOQL statements in an optimized and effective way.</p>
Table of Contents (14 chapters)
Getting Started with SOQL
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The ORDER BY clause


The ORDER BY clause in SOQL is used to sort the records retrieved in the ascending or descending order.

An ascending order sample query is given as follows:

SELECT Name, Amount FROM Opportunity ORDER BY Name ASC

The preceding query will retrieve all the Opportunity instances arranged in the ascending order of the name. The following screenshot is the output of the SOQL execution:

A descending order sample query is given as follows:

SELECT Name, Amount FROM Opportunity ORDER BY Name DESC

The preceding query will retrieve all the Opportunity instances arranged in the descending order of the name. The following screenshot is the output of the SOQL execution:

Note

Here, ASC means ascending order and DESC means descending order. By default, it will always be ascending order.