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
seshu.babu1.3923612903234636E12seshu.babu1.3923612903234636E12 

Trigger to fetch last 7 yrs records

I am new to write trigger. how to write a trigger to retrieve last 7 yrs old data and have to purge the data? If any one have the code please share. It will be very helpful for me.
sreenivasAppssreenivasApps
Hi Seshu,

here is an example query

SELECT Id FROM Account WHERE CreatedDate > LAST_N_YEARS:7

query whatever the fields you want !
Sagar PareekSagar Pareek
Hi Seshu,

What type of operation you want to do on last seven year data, do any field needs to be updated ? Can you please tell your use case?
seshu.babu1.3923612903234636E12seshu.babu1.3923612903234636E12
I want to delete the data I mean we do field value as null. and needs to delete the attachments in the Notes & Attachment section.
If you have any code please share.
sreenivasAppssreenivasApps
Hi seshu ,
please give the exact requirement 
seshu.babu1.3923612903234636E12seshu.babu1.3923612903234636E12
I want to create a purge process to purge Terminated Merchants’    Home address , Contact Number   from identified  related objects which are beyond the 7 yr retention policy
1.Go to account record
2.If “Account status” = CANCELLED/PAY OR CANCELLED/SUSPEND
3.The field in account “Cancel date”= True
4.Calculate seven years from the ‘Cancel Date”
5. The some address and phone field should be null