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
Julie Curry 19Julie Curry 19 

SOQL CreatedDate issue

My organization is looking to archive some records some I'm running some preliminary numbers for records we might want to archive.  I'd like to run a bunch of standard queries looking at records created >4 years ago.  When I add 'WHERE CreatedDate != LAST_N_DAYS:1460' at the end of my query I'm not getting anything. Is this the wrong way to do this query?
Thanks in advance for your help!
 
Ugur KayaUgur Kaya
Hi Julie,

If you are looking for the records which are created more than 4 years ago -> CreatedDate < LAST_N_DAYS:1460
If you are looking for the records which are created within the last 4 years -> CreatedDate = LAST_N_DAYS:1460

Regards.
Ugur
AbhishekAbhishek (Salesforce Developers) 
Julie, you have to make the query like the below

Sample Query

SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:365

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.