ApexSensei

All drills

SOQL queries: Apex practice drills

SOQL and SOSL: filters, bind variables, relationships, aggregates, date literals and safe dynamic queries.

Intermediate · Check and Run with Apex Path ($19 a month).

  1. Query one Account Beginner · 8 min

    SOQL reads Salesforce records into Apex.

  2. Filter Account names Beginner · 12 min

    WHERE keeps rows that meet a condition.

  3. Rank practice Accounts Beginner · 10 min

    ORDER BY sets the result order and LIMIT caps the row count.

  4. Bind an Account name Beginner · 12 min

    A bind variable puts an Apex value into SOQL with :variable.

  5. Match an Account list Beginner · 12 min

    IN :collection matches any value in a Set or List.

  6. Find missing Contact emails Beginner · 12 min

    SOQL uses = null and != null to find fields that are empty or filled in.

  7. Read a Contact's Account Intermediate · 14 min

    A child-to-parent query uses dot notation.

  8. Load Account Contacts Intermediate · 15 min

    A parent-to-child subquery pulls Accounts and their Contacts in one SOQL.

  9. Find Accounts by Contact Intermediate · 15 min

    A semi-join (Id IN (SELECT AccountId FROM Contact ...)) keeps parent rows that have a matching child.

  10. Summarize Opportunity amounts Intermediate · 15 min

    COUNT() counts rows and must sit alone in its SELECT.

  11. Keep busy Account groups Intermediate · 18 min

    GROUP BY returns one row per value.

  12. Stream tagged Accounts Intermediate · 15 min

    A SOQL for loop puts the query right in the loop header.

  13. Search safely with dynamic SOQL Intermediate · 18 min

    Dynamic SOQL that glues in user input lets a quote rewrite the query.

  14. Filter with date literals Intermediate · 18 min

    SOQL date literals (TODAY, NEXT_N_DAYS:30, LAST_N_DAYS:30) are evaluated at query time in the user's time zone.

  15. Search names with SOSL Intermediate · 18 min

    SOSL searches text across several objects at once and returns one list per object, in the order you wrote after RETURNING.

  16. Single-row query: zero or many rows Intermediate · 13 min

    A SOQL query that assigns straight into an sObject throws when the match count is 0 or more than 1.

  17. WITH USER_MODE versus system mode Intermediate · 13 min

    Apex SOQL runs in system mode by default.

  18. Group by a parent field Intermediate · 14 min

    GROUP BY <field> collapses rows that share a value into one summary row.

  19. Multi-level relationships with __r Intermediate · 14 min

    Dot notation walks lookup fields in the SELECT.

  20. Paging with LIMIT and last-value Intermediate · 15 min

    LIMIT caps rows per page.

Start practicing free