+ Start a Discussion
HNT_NeoHNT_Neo 

How to cancel an apex batch job

Hello, 
Trying to cancel an apex batch job but no luck making it work. 

This is the apex code I'm using and the error results are below. Any help is greatly appreciated!
 
string SCHEDULE_NAME = 'MergeMetricsCalculationBatchable';
System.abortJob(SCHEDULE_NAME);
 
Execute anonumous error

Line: 2, Column: 1
System.StringException: Only CronTrigger IDs and batch, future, and queueable job IDs are supported.

 
Best Answer chosen by HNT_Neo
Raj VakatiRaj Vakati
You need to pass the job Id 


 Run the following query to find the scheduled or future Apex job id to delete:
 
SELECT ApexClassId,CompletedDate,CreatedById,CreatedDate,ExtendedStatus,Id,JobItemsProcessed,JobType,LastProcessed,LastProcessedOffset,MethodName,NumberOfErrors,ParentJobId,Status,TotalJobItems FROM AsyncApexJob where status = 'queued'

.Pass the job Id here 
 
System.abortJob('JobID');
Refer this link 

https://help.salesforce.com/articleView?id=000003873&type=1

OR 

Go to Setup>Monitor>Jobs>Scheduled Jobs --> Delete from here also 


 

All Answers

Raj VakatiRaj Vakati
You need to pass the job Id 


 Run the following query to find the scheduled or future Apex job id to delete:
 
SELECT ApexClassId,CompletedDate,CreatedById,CreatedDate,ExtendedStatus,Id,JobItemsProcessed,JobType,LastProcessed,LastProcessedOffset,MethodName,NumberOfErrors,ParentJobId,Status,TotalJobItems FROM AsyncApexJob where status = 'queued'

.Pass the job Id here 
 
System.abortJob('JobID');
Refer this link 

https://help.salesforce.com/articleView?id=000003873&type=1

OR 

Go to Setup>Monitor>Jobs>Scheduled Jobs --> Delete from here also 


 
This was selected as the best answer
HNT_NeoHNT_Neo
Raj, apparently I had already deleted it, however, this is a good reference for all to see. Thank you!
Ajay K DubediAjay K Dubedi
Hi JH_Neo,
You can go with this code:
public class AbortScheduledJob {
    public static void abortScheduledJob () {
        CronTrigger abort_job = [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name = : 'ScheduleClass' limit 1];
            System.abortJob(abort_job.Id); //abort the job
        }   
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
job alertjob alert
Okay prefer to land all forthcoming Govt Positions 2019? Fresherslive is here to give snappy updates of most recent Govt Jobs right away. Free notice of up and coming Government Jobs in India 2019 warning buy govt jobs (https://www.highonstudy.com/government-jobs) in to our page and discover recently reported All Govt Jobs October crosswise over India first on Fresherslive refreshed on 31-10-2019.
pvtbank jobspvtbank jobs
Bank workers are commonly very efficient and have solid PC abilities. They likewise have great relational abilities, are incredible at managing individuals, and are administration situated.  Bank Jobs Monetary organizations recruit up-and-comers who are straightforward and reliable. They additionally search for individuals who can ascertain and adjust numbers effectively. As the government directs numerous parts of the financial business, their workers are needed to hold fast to every one of the guidelines and guidelines that banks should follow.
 
Cyberpower CyberpowerCyberpower Cyberpower
Comparing the two becomes very intricate due to the fact those are pre-constructed structures. https://devicemaze.com/ibuypower-vs-cyberpower/  We can not absolutely compare custom-built systems from the 2 businesses because each of them may have identical specifications, assessment will most effective lie in rate. However, for this text, we've got determined to compare the bottom-priced pre-built structures and the very best priced prebuilt structures of the two brands.
 
Daniel GiriDaniel Giri
Why aren't you switching to a better monitor for all your salesforce needs? A bigger display would help you to manage your tasks more better and see more data at once. And to find good monitors, you can check best monitor for 2070 super (https://bestmonitorpicks.com/for-rtx-2070-super/) list.