SalesforceTrailhead
  • Today
© 2026 Salesforce, Inc. All rights reserved. Privacy Terms of Use Trust Accessibility Cookie Preferences
Apex Basics & Database

Write SOQL Queries

+500 Points~40 minsHands-On Challenge
Apex Basics & DatabaseWrite SOQL Queries

Org:Mindful Goat Playground

Topics

  • Concepts
  • Hands-On Challenge

Looking for help?

Explore Help ResourcesShare Your Feedback
Learning Objectives

After completing this unit, you'll be able to:

  • Write SOQL queries in Apex.
  • Filter and sort query results.

Concepts

SOQL reads records. Write it inline in square brackets, filter with WHERE, and sort with ORDER BY. Bind Apex variables with a colon.

Hands-On Challenge

  1. Create a class ContactSearch with a static method searchForContacts(String lastName, String postalCode).
  2. Return the ID and Name of contacts that match both values.
List<Contact> results = [SELECT Id, Name FROM Contact
                          WHERE LastName = :lastName AND MailingPostalCode = :postalCode];
Check ChallengeDemo check
Previous UnitManipulate Records with DMLNext Unit Write SOSL Queries