This question runs in a pre-configured Salesforce environment - no personal connection required.
Write a method that uses SOQL GROUP BY to create a summary report of contacts by department. The method should return a Map<String, Integer> where the key is the department name and the value is the count of contacts in that department. Only include departments that have at least one contact.
This challenge tests your ability to use SOQL aggregation functions with GROUP BY to summarize data and work with Map collections.
Examples
Input: None (method queries all contacts)
Output: {
'Technology' => 6,
'Executive' => 5,
'Sales' => 3,
'Operations' => 4,
'Product' => 3,
'Finance' => 1,
'R&D' => 2,
...
}
Explanation: Returns count of contacts grouped by department
Input: If all contacts have null departments
Output: {}
Explanation: Returns empty map when no departments are defined
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 July 2026
Contest runs July 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.