You need to sign in to do that
Don't have an account?

How do I write a code that deletes the right records if the record is idle for more than 180 days. Can anyone share me the code for this synario ??
How do I write a code that deletes the right records if the record is idle for more than 180 days. Can anyone share me the code for this synario ??
Hi,
Please refer the below sample code. Save this class, and Schedule this class to RUN DAILY.
To Schedule, Click setup --> Apex Class --> Click the Button "Schedule Apex" and choose this class name and provide the other required details.
global class SchClass_DeleteUnUsedRecords implements Schedulable {
global void execute(SchedulableContext ctx) {
Date DateCriteria = Date.Today().addDays(-180);
List<Account> ListofAccounts = new List<Account> ();
ListofAccounts = [SELECT id, lastModifiedDate FROM Account WHERE lastModifiedDate <: DateCriteria];
if(!ListofAccounts.isEmpty()){
system.debug('ListofAccounts'+ListofAccounts);
Delete ListofAccounts;
}
}
}
Hope this addressed your Query.
And one more suggestion is, Please dont misuse this community by just asking the Code..
Thanks
Syed Moosa Nazir TN
smartmoosa@gmail.com
I would suggest you to write a batch and shedule that batch to run eveyday to avoid any issues -
You can go through this link, it may be useful to you -
https://developer.salesforce.com/forums/?id=906F00000009357IAA