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