You need to sign in to do that
Don't have an account?
Shubhangi Jadhav
Can anyone help me to write batch class to delete records last modified 7 days
I wrote below code on Product object to test:
I want
"Days parameter should be configurable"
How can i use label for days
global class TetCleanupBacth_Product implements Database.Batchable<sObject>,Schedulable{
static Date today1 = Date.today().addDays(-1);
public Database.QueryLocator start(Database.BatchableContext context)
{
return Database.getQueryLocator('Select ID from Tet_LoadProduct__c where LastModifiedDate < :today1' AND status__c in ('Success','Processed'));
}
global void execute(Database.BatchableContext context, List<SObject> records)
{
delete records;
}
global void execute(SchedulableContext ctx)
{
Database.executeBatch(new TetCleanupBacth_Product());
}
global void finish(Database.BatchableContext BC) {
}
}
But getting error while saving.
I want
"Days parameter should be configurable"
How can i use label for days
global class TetCleanupBacth_Product implements Database.Batchable<sObject>,Schedulable{
static Date today1 = Date.today().addDays(-1);
public Database.QueryLocator start(Database.BatchableContext context)
{
return Database.getQueryLocator('Select ID from Tet_LoadProduct__c where LastModifiedDate < :today1' AND status__c in ('Success','Processed'));
}
global void execute(Database.BatchableContext context, List<SObject> records)
{
delete records;
}
global void execute(SchedulableContext ctx)
{
Database.executeBatch(new TetCleanupBacth_Product());
}
global void finish(Database.BatchableContext BC) {
}
}
But getting error while saving.
Can you mention the error you are facing while saving the above class?
Also, I think you can use UI to schedule the above class.
Looking forward for your response.
Regards,
Anutej
Thanks for your response.I am getting error for Query.
Please find attchmemt.
How i can save Days in any label and chnage at any time without touching to code?
Regards,
Shubhangi
String query = 'Select ID from Tet_LoadProduct__c where LastModifiedDate < :today1' AND status__c in :statusset' ;
return Database.getQueryLocator(query);
Can you try using the above lines once.