DocSF

DocSF

Did You Know?

Advanced visual search system powered by Ajax

Salesforce Schedule Batch

This script helps you to schedule/deschedule current Apex Batch Jobs

				
					String NameOfBatch = 'Name Of Batch';
Set<String> existingJobNames = new Set<String>();
List<CronTrigger> existingScheds = [SELECT Id, CronJobDetail.Name FROM CronTrigger WHERE CronJobDetail.JobType = '7'];
for (CronTrigger ct : existingScheds)
{
	existingJobNames.add(ct.CronJobDetail.Name);
}

if (!existingJobNames.contains(NameOfBatch)){
	NameOfBatch_Sch b = new NameOfBatch_Sch();
	String sch_b = '0 0 9 ? * 1,2,3,4,5,6,7';
	System.schedule(NameOfBatch, sch_b, b);
}


//#### DESCHEDULE BATCH ####
String NameOfBatch = 'Name of batch';
Set<String> jobNames = new Set<String>{		
	NameOfBatch};

List<CronTrigger> cronTriggers = [SELECT Id,TimesTriggered, NextFireTime, CronJobDetail.Id, CronJobDetail.Name, CronJobDetail.JobType
								  FROM CronTrigger where CronJobDetail.JobType = '7' AND CronJobDetail.Name IN :jobNames
									ORDER BY CreatedDate DESC];
if (cronTriggers.isEmpty()){
	system.debug('Non è stato trovato nessun processo Apex schedulato. Impossibile deschedulare.');
}
for (CronTrigger ct : cronTriggers){
	System.abortJob(ct.Id);
}				
			

Related Post

 I futures dell’Oro sono in ribasso d

Nel divisione Comex del New York Mercantile Exchange, ...

Come mettersi in proprio

Credo che in ogni persona, di tanto in tanto emerga la ...

A cosa serve il domino .cloud

La storia del dominio .cloud è tutta italiana, siamo n...

Leave a Comment