ApexSensei

All drills

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)

  1. Query one Account (Beginner, 8 min)
    Create one tagged Account, select its Id and Name, and verify the exact record returned.
  2. 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.
  3. Rank practice Accounts (Beginner, 10 min)
    Sort four tagged Account names descending and keep only the first two records.
  4. 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.
  5. 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.
  6. Find missing Contact emails (Beginner, 12 min)
    Query tagged Contacts with and without an Email, including the edge case of a blank Email.
  7. 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.
  8. 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.
  9. 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.
  10. Summarize Opportunity amounts (Intermediate, 15 min)
    Compare row and non-null counts, then calculate SUM and AVG for tagged Opportunities.
  11. Keep busy Account groups (Intermediate, 18 min)
    Group tagged Opportunities by Account and keep groups with at least two rows.
  12. 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.
  13. 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.
  14. 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.
  15. 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.

Start practicing free