function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakesh teja 4Rakesh teja 4 

Delete accounts every Monday 5am if account type='Othres' Write only Schedule apex ?

AubryAubry
Yes, you probably need scheduled apex.

I strongly recommend you check out the trailhead for it: https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_scheduled
Khan AnasKhan Anas (Salesforce Developers) 
Hi Rakesh,

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.
global class Schedule_DeleteAccount implements Schedulable{
    
    global void execute(SchedulableContext SC) {
        deleteacc();
    }
    
    public static void deleteacc() {
        delete [SELECT Id FROM Account WHERE Type ='Other'];
    }
}

And you can schedule it using Cron:
Schedule_DeleteAccount sch = new Schedule_DeleteAccount();
System.schedule('WeeklyBatch', '0 0 5 ? * MON', sch);

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