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

Return the StageName that appears on more Opportunity records than any other stage.

When two or more stages are tied for the most records, return the one that comes first alphabetically. If the org holds no Opportunity records at all, return null.

Do this with a single aggregate query rather than by looping over every record.

Examples:

Input: (no parameters — the method reads the org) Output: 'Closed Won' Explanation: More Opportunity records sit in Closed Won than in any other stage Tie handling: Stage counts { 'Negotiation/Review' => 6, 'Proposal/Price Quote' => 6 } Output: 'Negotiation/Review' Explanation: Both stages hold 6 records so the alphabetically first name wins Empty org: Output: null Explanation: With no Opportunity records there is no most common stage
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 November 2026 (Nov 16–30)Sponsored by FLXBL

Contest runs November 16 - 30. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 15 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