Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
global class Schedule_DeleteAccount implements Schedulable{
global void execute(SchedulableContext SC) {
deleteacc();
}
public static void deleteacc() {
delete [SELECT Id FROM Account WHERE Type ='Other'];
}
}
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
I strongly recommend you check out the trailhead for it: https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_scheduled
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
And you can schedule it using Cron:
Please refer to the below links which might help you further.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm
https://webkul.com/blog/cron-expression-for-scheduling-jobs-in-salesforce/
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas