This question runs in a pre-configured Salesforce environment - no personal connection required.
Return the names of the top N accounts sorted by AnnualRevenue in descending order. Only include accounts with non-null AnnualRevenue values. If the limit is less than 1, return an empty list.
Write a method that accepts an Integer representing the number of top accounts to retrieve and returns a List of String containing the account names.
Examples
Example 1: Basic Usage
Input: topN = 3
Output: ['Account A', 'Account B', 'Account C']
Explanation: Returns the 3 accounts with the highest revenue values, sorted in descending order by AnnualRevenue.
Example 2: Zero Limit
Input: topN = 0
Output: []
Explanation: When the limit is zero or negative, return an empty list.
Example 3: Limit Larger Than Data
Input: topN = 100
Output: List of all accounts with non-null revenue
Explanation: If the limit exceeds the number of accounts with revenue data, return all qualifying accounts.
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
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.