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

Query all Opportunities and calculate the average number of days each Opportunity has existed. Group the results by StageName and return a Map where keys are stage names and values are the average duration in days. For open opportunities (IsClosed = false), calculate days from CreatedDate to today. For closed opportunities (IsClosed = true), calculate days from CreatedDate to CloseDate.

Examples:

Input: No parameters Output: {'Prospecting' => 45.5, 'Qualification' => 32.3, 'Closed Won' => 15.0} Explanation: Average days for Prospecting stage is 45.5, Qualification is 32.3, Closed Won is 15.0 Input: No parameters Output: {'Negotiation' => 22.7} Explanation: Only one stage exists with average of 22.7 days
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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In