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!
How It Works
- • Write your solution in the code editor
- • This challenge runs without connecting your own org
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay August 2026
Contest runs August 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.