This question runs in a pre-configured Salesforce environment - no personal connection required.

Query and return all Contact records where the LeadSource field matches the given value. Return results ordered by LastName ascending. Return an empty list if leadSource is null or blank.

The LeadSource field tracks how a contact was originally acquired by your organization. This is important for marketing analytics and understanding which channels bring in the most contacts.

Method Signature

public static List<Contact> getContactsByLeadSource(String leadSource)

Examples

Input: leadSource = 'Web' Output: List of 8 Contact records with LeadSource = 'Web' Explanation: Returns all contacts acquired via Web, ordered by last name
Input: leadSource = 'Trade Show' Output: List of 6 Contact records with LeadSource = 'Trade Show' Explanation: Returns all contacts acquired at trade shows
Input: leadSource = 'Unknown Source' Output: [] Explanation: No contacts match this lead source
Input: leadSource = null Output: [] Explanation: Null lead source returns empty list
Apex Code Editor

Welcome to Lightning Challenge!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay May 2026

Contest runs May 1 - 31. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In