Write a method that updates Account ratings based on AnnualRevenue thresholds. The method should set Rating to "Hot" if revenue is greater than or equal to 50,000,000, "Warm" if revenue is greater than or equal to 10,000,000, and "Cold" for all other cases (including null revenue).
The method should:
- Accept a list of Account records as a parameter
- Update the Rating field based on AnnualRevenue thresholds
- Handle null AnnualRevenue values by setting Rating to "Cold"
- Use Database.update for bulk-safe operations
- Return the count of accounts successfully updated
Method Signature
public static Integer updateAccountRatings(List<Account> accounts)
Examples
Example 1:
Input: accounts with AnnualRevenue values [60000000, 25000000, 5000000]
Output: 3
Explanation: Updated 3 accounts - first to "Hot", second to "Warm", third to "Cold"
Example 2:
Input: accounts with AnnualRevenue values [null, null]
Output: 2
Explanation: Updated 2 accounts with null revenue to "Cold" rating
Example 3:
Input: empty list of accounts
Output: 0
Explanation: No accounts to update, returns 0
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.