Query the org (SOQL): Apex practice drills
SOQL and SOSL: filters, bind variables, relationships, aggregates, date literals and safe dynamic queries.
15 drills · Intermediate · Free to read, run with Apex Path ($19/month after a 7-day trial)
- Query one Account (Beginner, 8 min)
Create one tagged Account, select its Id and Name, and verify the exact record returned. - Filter Account names (Beginner, 12 min)
Build a LIKE pattern that finds tagged Accounts whose names start with North, in any letter case, and skips close decoys. - Rank practice Accounts (Beginner, 10 min)
Sort four tagged Account names descending and keep only the first two records. - Bind an Account name (Beginner, 12 min)
Bind Apex String values into SOQL, including a name with an apostrophe and a name that matches nothing. - Query with a Set of Ids (Beginner, 12 min)
Collect Account Ids from a list of Contacts into a Set, then load those Accounts with one IN query. - Find missing Contact emails (Beginner, 12 min)
Query tagged Contacts with and without an Email, including the edge case of a blank Email. - Read a Contact's Account (Intermediate, 14 min)
Read Account.Name through each tagged Contact, and use it safely for a Contact that has no Account. - Load Account Contacts (Intermediate, 15 min)
Use a parent-to-child subquery to load two tagged Accounts with their Contacts, including an Account with none. - Find Accounts by Contact (Intermediate, 15 min)
Use IN and NOT IN with a Contact subquery to find tagged Accounts that do and don't have a matching Contact. - Summarize Opportunity amounts (Intermediate, 15 min)
Compare row and non-null counts, then calculate SUM and AVG for tagged Opportunities. - Keep busy Account groups (Intermediate, 18 min)
Group tagged Opportunities by Account and keep groups with at least two rows. - Loop over Accounts in chunks (Intermediate, 15 min)
Use a SOQL for loop to process 201 tagged Accounts in chunks of 200, and see how the two loop forms behave when a query matches nothing. - Search safely with dynamic SOQL (Intermediate, 18 min)
Fix a dynamic SOQL search so a quote in the input cannot rewrite the query, using queryWithBinds or escapeSingleQuotes. - Filter with date literals (Intermediate, 18 min)
Count tagged Opportunities with SOQL date literals such as NEXT_N_DAYS, LAST_N_DAYS and TODAY instead of computed dates. - Search names with SOSL (Intermediate, 18 min)
Run one SOSL search across Accounts and Contacts, return the names in a set order, and see why tests need Test.setFixedSearchResults.