+ Start a Discussion
ManidManid 

write cronexpresion for deletion of the leads in every weekend 10 Pm

Suraj TripathiSuraj Tripathi
Hi Manid,

First you have to create Batch class to delete the lead:

 
global class DeleteLead implements Database.Batchable<SObject>
	{
		global Database.QueryLocator start(Database.BatchableContext BC)
		{
        	string query = 'select id  from Lead;
        	System.debug('-----------1'+query);
        	return Database.getQueryLocator(query);
		}
		global void execute(Database.BatchableContext BC, List<Account>scope)
		{
			for(Lead acc:scope)
        	if(scope.size()>0)
        	system.debug('------------'+scope);
        	delete scope;
		}
		global void finish(Database.BatchableContext BC)
		{
			system.debug('Lead Deleted');
		}
		
	}

Then Create the Scheduler class: The Schedulable  class will delete the lead every Saturday.
 
public class LeadSchedule implements Schedulable  
{
	public static void SchuduleMake()
	{
		String cron='0 0 22 ? * SAT *';
		System.schedule('hello',cron,new Batch2());	
		
	} 
	
    public void execute(SchedulableContext sc) 
    {
    	
     	DeleteLead b=new DeleteLead();
     	Database.executeBatch(b);
		
    }
}

Hope it will help you If it resolves your query. please Mark the best answer.

Regards,
Suraj

 
ManidManid
thanks you so much its works