Create a method that takes a Map<String, Integer> and returns the sum of all values in the map. This is a fundamental operation when aggregating data from maps, commonly used in reporting scenarios.

In Salesforce, this pattern appears frequently when you need to calculate totals from grouped data, such as counting records by category, summing points by user, or aggregating revenue by region.

Examples:

Input: valueMap = {'Sales' => 100, 'Marketing' => 200, 'Engineering' => 150}
Output: 450
Explanation: Sum of 100 + 200 + 150 equals 450

Input: valueMap = {'Product' => 500}
Output: 500
Explanation: Single entry map returns that value

Input: valueMap = {}
Output: 0
Explanation: Empty map returns 0

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 Jan 2026

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

Points are calculated for challenges completed during the contest period.