+ Start a Discussion
gowtham murugesangowtham murugesan 

Hi all, am new to this Scheduled APEX,Kindly help me out

Need to fetch the deleted record id for every 3 minutes and want to save that id into some custom object.Please give me a solution.
Thanks in advance.
Raj VakatiRaj Vakati
Use this class
 
global class DeleteCustomObject implements Schedulable{

    global void execute(SchedulableContext SC) {
        deleteRecord();
    }

    public static void deleteRecord() {

        for(List<Custom_object__c> objoppo : [SELECT Id FROM Custom_object__c ])
            {
                delete objoppo;
            }    
    }
}

By default you can run apex job every 1 hour using cron expression but you can schedule this job 12 times at 5 min duration. However only 100 Apex classes can be scheduled concurrently and 5 batch Apex jobs can be queued or active concurrently.

 
String sch1 = '0 0 * * * ?';
DeleteCustomObject sqrb1 = new DeleteCustomObject ();
system.schedule('Every Hour plus 0 min', sch1, sqrb1);

String sch2 = '0 3 * * * ?';
DeleteCustomObject sqrb2 = new DeleteCustomObject ();
system.schedule('Every Hour plus 3 min', sch2, sqrb2);


.
//You get the idea.
.
.
.
.
String sch12 = '0 60 * * * ?';
DeleteCustomObject sqrb12 = new DeleteCustomObject ();
system.schedule('Every Hour plus 60 min', sch12, sqrb12 );