function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Madhuri LondheMadhuri Londhe 

SOQL query to get records created date greater than 5 years .

Hi,

I need to write a batch class on one of object records whose created date  greater than 5 years .
Please help me to write correct filter condition for this.
Best Answer chosen by Madhuri Londhe
Soyab HussainSoyab Hussain
Hi Madhuri,

You can use LAST_N_YEARS Date Literals in your batch, this will help you.
SELECT Id FROM Opportunity WHERE CloseDate > LAST_N_YEARS:5

If you found it useful please appreciate my efforts and mark it as the best answer.

LinkedIn: https://www.linkedin.com/in/soyab-hussain-b380b1194/ 

Regards,
Soyab

All Answers

Soyab HussainSoyab Hussain
Hi Madhuri,

You can use LAST_N_YEARS Date Literals in your batch, this will help you.
SELECT Id FROM Opportunity WHERE CloseDate > LAST_N_YEARS:5

If you found it useful please appreciate my efforts and mark it as the best answer.

LinkedIn: https://www.linkedin.com/in/soyab-hussain-b380b1194/ 

Regards,
Soyab
This was selected as the best answer
Madhuri LondheMadhuri Londhe
Hi Soyab,

Thank you. Its working fine for me.
Soyab HussainSoyab Hussain
My pleasure, Madhuri.