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

🏆 #CodeEveryDay August 2026

Contest runs August 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