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

Return the top N accounts by annual revenue for a specified country. The accounts should be sorted by revenue in descending order (highest revenue first). If the country is null or if topN is less than or equal to 0, return an empty list. If there are fewer accounts in the country than topN, return all accounts from that country.

Examples:

Input: country = "USA", topN = 3
Output: List of top 3 USA accounts sorted by AnnualRevenue descending
Explanation: Returns the 3 highest revenue accounts from USA

Input: country = "Germany", topN = 1
Output: List with the single highest revenue German account
Explanation: Returns only the top account from Germany

Input: country = null, topN = 5
Output: Empty list
Explanation: Null country returns empty list

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