This question runs in a pre-configured Salesforce environment - no personal connection required.
Write a method that applies a percentage discount to the Amount of every open Opportunity in the input list. An open Opportunity is one whose IsClosed flag is false. Closed Opportunities and Opportunities with a null Amount must be skipped. The method must update the records in the database using DML and return the number of records updated. If the input list is null or empty, or the percent is null, return 0 without performing any DML.
Examples:
Method signature:
public static Integer applyDiscount(List<Opportunity> opps, Decimal percent)
Behavior:
- Skips closed opportunities and opportunities with null Amount
- Updates each qualifying opportunity Amount to Amount * (1 - percent / 100)
- Performs a single bulk update
- Returns the count of records updated
Sample calls:
applyDiscount(null, 10) -> 0
applyDiscount(new List<Opportunity>(), 10) -> 0
applyDiscount(opportunities, null) -> 0
applyDiscount(openOpps, 10) -> opp count discounted by 10%
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
🏆 All Time Leaderboard
Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.