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
sparc1.3696571782628958E12sparc1.3696571782628958E12 

Scheduled the deletion of records based on a specific Criteria

Hi All

 

I wish to delete records from my Opportunity Object based on a criteria, i.e. for those where Amount < 500000.

 

I wish to schedule this such that this deletion automatically takes place on every specific date ( say 1st of every month).

 

Thanks in Advance!!!

 

Shiv

sfdcfoxsfdcfox
You can write a scheduled apex class to accomplish this. The following developer page is relevant to your goal:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm
souvik9086souvik9086

global class ScheduledApexForBulkDelete implements Schedulable {
    global void execute(SchedulableContext ctx) {
        
        //Bulk Delete of unwanted Record
        //Your code to delete Opportunity based on criteria        
    }

public static testMethod void testschedule() {

        Test.StartTest();

        ScheduledApexForBulkDelete  sh1 = new ScheduledApexForBulkDelete();
        String sch = '0 0 23 * * ?';
        System.assert(sch == '0 0 23 * * ?');
        system.schedule('Test Territory Check', sch, sh1);
        Test.stopTest();

    }

 

}

 

You can can create this class and then go to Apex classes and click Schedule Apex.

In that section you select that class and select date-time when to run.

You can see the scheduled jobs in:-

SetUp -> Administration Setup -> Monitoring -> Scheduled Jobs

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks