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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.