Salesforce 是否可以使用CronTrigger作业ID来确定作业是否已中止或无效?
在实现System.Schedulable的Apex类中,我有一个函数作为重调度逻辑的一部分被调用Salesforce 是否可以使用CronTrigger作业ID来确定作业是否已中止或无效?,salesforce,apex,apex-code,Salesforce,Apex,Apex Code,在实现System.Schedulable的Apex类中,我有一个函数作为重调度逻辑的一部分被调用 @TestVisible private void reschedule(CronTrigger me, ISchedulable item, MySchedulableContext myCtx) { try { System.abortJob(me.Id); } catch(Exception e) { Syste
@TestVisible private void reschedule(CronTrigger me, ISchedulable item, MySchedulableContext myCtx) {
try {
System.abortJob(me.Id);
} catch(Exception e) {
System.debug('Unable to abort the job');
}
String newTrigger = item.getNextTriggerString(myCtx);
if (newTrigger != null && newTrigger.length() > 0) {
try {
System.schedule(me.CronJobDetail.Name+ '-' + System.currentTimeMillis(), newTrigger, this);
} catch(Exception e) {
System.debug('Unable to start the job');
}
}
}
我如何知道我将要中止的作业是否尚未中止,或者我将要启动的作业是否尚未启动?是的,try/catch将处理错误,但是我想更好地理解这一点您可以查询对象以获取作业的状态
你可以这样做:
SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors
FROM AsyncApexJob WHERE ID = :jobId
如果愿意,请检查状态。可用状态如下所示:
- 持有
- 排队
- 准备
- 加工
- 流产
- 完成
- 失败