For the complete documentation index, see llms.txt. This page is also available as Markdown.

Introduction to SOQL

Basic Structure

SELECT field1, field2, field3
FROM ObjectName
WHERE conditions
ORDER BY field ASC|DESC
LIMIT number

Important SOQL Features

  • SELECT fields

  • WHERE filters (text, number, date, boolean, IN, LIKE, etc.)

  • ORDER BY (ASC/DESC, NULLS FIRST/LAST)

  • LIMIT / OFFSET

  • Aggregate functions (COUNT(), SUM(), AVG(), MIN(), MAX())

  • GROUP BY / HAVING

  • Parent-to-child subqueries

  • Child-to-parent traversals

Looking for something more advanced? Explore our running list of SOQL queries for S-Docs and S-Sign!

SOQL Examples (10 Practical Examples)

1

Basic Query

Return ID, name, and industry of all accounts:

2

Filtering with WHERE

Return name and annual revenue of accounts with greater than 1,000,000 annual revenue:

3

Filtering Using LIKE (Wildcards)

Fetch contact names whose email ends with '@gmail.com':

4

Using IN to Match Multiple Values

Return ID and status for cases that has 'New', 'Working', or 'Escalated' status:

5

Ordering Results

Return name, close date, and amount of all opportunities, ordered by newest created first:

6

Parent-to-Child (Subquery)

Returns ID, Name, and all associated OpportunityLineItems for the opportunity with ID = '006XXXXXXXXXXXX':

7

Child-to-Parent (Dot Notation)

Fetch all contact's ID, name, and their parent account's name and industry:

8

Aggregate Query

Return status and the count of cases for each status:

9

Aggregate with HAVING

Only return status and count of cases for each status that has more than 50 cases:

10

LIMIT and OFFSET

Skip the first 20 leads and return the next 20 leads, sorted by newest first:

Last updated

Was this helpful?