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

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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In