You need to sign in to do that
Don't have an account?
Delete all records in a custom table
Hi There,
We have a requirement to delete all data in a custom object daily and load it from external data source.
We have a APEX class as per below:
@RestResource(urlMapping='/DeleteRecords/*')
global with sharing class DeleteRecords
{
@HttpDelete
global static void doDelete()
{
List<MTDYTD_Trend_Data__c> customObj = [select Id FROM CustomObject LIMIT 10000];
if(!customObj.isEmpty())
delete customObj;
}
}
As we are calling this class from external source and the records are above 10 K it fails. How can we tweak the above to run it in a loop till the entire records in the object is cleared out?
Please advise.
Thank you.
I think a batch class which deletes records can work and can be executed from this method, give it a try.
Thanks
Try The Following Code Please Mark It As Best Answer If It Helps
Thank you.
Thanks Charu.
Can this be exposed as REST?
You can call batch apex from rest apex class.