You need to sign in to do that
Don't have an account?
santhosh konathala 17
Can anybody help how to delete records older than 30 days in an object.The below code is not fetching records.Please help me..
global class TechMDeletion implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext bc)
{
date d=system.today().adddays(-30);
return Database.getQueryLocator([Select id from TechM__c where CreatedDate =:d]);
}
global void execute(Database.BatchableContext BC, list<sObject> scope)
{
system.debug('records fetched are'+scope);
delete scope;
DataBase.emptyRecycleBin(scope);
}
global void finish(Database.BatchableContext BC)
{
}
}
{
global Database.QueryLocator start(Database.BatchableContext bc)
{
date d=system.today().adddays(-30);
return Database.getQueryLocator([Select id from TechM__c where CreatedDate =:d]);
}
global void execute(Database.BatchableContext BC, list<sObject> scope)
{
system.debug('records fetched are'+scope);
delete scope;
DataBase.emptyRecycleBin(scope);
}
global void finish(Database.BatchableContext BC)
{
}
}
In query editor u have to use below formate,
Select id from TechM__c where CreatedDate <= 2016-11-15T00:00:00Z
Select id from TechM__c where DAY_ONLY(CreatedDate) <= 2016-11-15
Select id from TechM__c where CreatedDate <= YESTERDAY
Select id from TechM__c where CreatedDate = TODAY
All Answers
global Database.QueryLocator start(Database.BatchableContext bc)
{
date d=system.today().adddays(-30);
return Database.getQueryLocator( 'Select id from TechM__c where CreatedDate <=:d' );
}
The below query not fetching records in query editor saying that unknown parsing query error....could you help on this
In query editor u have to use below formate,
Select id from TechM__c where CreatedDate <= 2016-11-15T00:00:00Z
Select id from TechM__c where DAY_ONLY(CreatedDate) <= 2016-11-15
Select id from TechM__c where CreatedDate <= YESTERDAY
Select id from TechM__c where CreatedDate = TODAY
your query saved me...