Skip to main content

Posts

Showing posts from April, 2025

📆 How to Get the Start and End Date of the Previous Quarter in Apex ?

 When working with Salesforce data, it's often necessary to filter or report on records from a specific quarter . If you're looking to retrieve the start and end dates of the previous quarter based on the current date, here’s a simple and reusable Apex utility you can use. 🔧 Apex Utility Methods Below are two helper methods: getStartDate() — Calculates the start date of the previous quarter . getEndDate() — Calculates the end date of the previous quarter , based on the start date. // Helper method to get the start date of the previous quarter private Date getStartDate () {     Date today = Date . today ();     Integer currentYear = today . year ();     Integer currentMonth = today . month ();     // Determine the first month of the previous quarter     Integer previousQuarterStartMonth = (( currentMonth - 1 ) / 3 ) * 3 + 1 - 3 ;     // Adjust the year if the previous quarter falls in the previ...