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!
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.