Given a Date value, return a new Date representing the first day of the same month and year. The day component is always 1.

Examples:

Input: d = Date.newInstance(2024, 6, 15) Output: Date.newInstance(2024, 6, 1) Explanation: Returns the first day of June 2024 Input: d = Date.newInstance(2024, 1, 31) Output: Date.newInstance(2024, 1, 1) Explanation: Returns the first day of January 2024 Input: d = Date.newInstance(2024, 12, 25) Output: Date.newInstance(2024, 12, 1) Explanation: Returns the first day of December 2024 Input: d = Date.newInstance(2024, 2, 29) Output: Date.newInstance(2024, 2, 1) Explanation: Returns the first day of February 2024 (leap year) Input: d = Date.newInstance(2023, 11, 1) Output: Date.newInstance(2023, 11, 1) Explanation: Already the first day of the month, returns the same date
Apex Code Editor

Welcome to Lightning Challenge!

How 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

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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In