我遇到的问题是我的批处理作业在记录上运行了两次,有人可以告诉我如何检查...
global class SVMXC_BatchCallClosureGlobal implements Database.Batchable<sObject>, Database.AllowsCallouts {
public String query = 'SELECT Id, Case__c, Case__r.Sales_Organisation_From_IP__c, Re_Update__c, SVMXC_Batch_Picked_Up__c, Result__c,SVMX_Retry_XML__c, CreatedDate ' +
'FROM OutBoundMWLog__c ' +
'WHERE ((SVMXC_Batch_Picked_Up__c = false AND Result__c = null) ' +
'OR Re_Update__c = false OR SVMX_Retry_XML__c =true) and Case__r.Sales_Organisation_From_IP__c IN :globalSap';
Set<String>globalSap = new Set<String>();
List<Sales_Org_with_Region_and_Country__c> settingValues = Sales_Org_with_Region_and_Country__c.getall().values();
public SVMXC_BatchCallClosureGlobal() {
for (Sales_Org_with_Region_and_Country__c setting : settingValues) {
if (setting.SAP_Application__c != null && setting.SAP_Application__c.equals('Global SAP')) {
globalSap.add(setting.Sales_Org__c);
}
}
}
global Database.Querylocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List <sObject> scope) {
Set<Id> caseIdSetforGlobal = new Set<Id>();
Set<Id> caseIdSet = new Set<Id>();
DateTime now = system.now().addMinutes(-3);
for (OutBoundMWLog__c obound : (List<OutBoundMWLog__c>) scope) {
if (obound.CreatedDate <= now || Test.isRunningTest()) {
obound.SVMXC_Batch_Picked_Up__c = true;
obound.Re_Update__c = true;
caseIdSet.add(obound.Case__c);
}
}
//Query for the case's Sales organisation from the caseIdSet.
List<Case> caseList = new List<Case>([select id, Sales_Organisation_From_IP__c from case where id in: caseIdSet]);
for (Case cs : caseList) {
if (globalSap.contains(cs.Sales_Organisation_From_IP__c)) {
caseIdSetforGlobal.add(cs.id);
}
}
system.debug('******caseIdSetforGlobal*********' + caseIdSetforGlobal);
if (!caseIdSetforGlobal.isEmpty()) {
ServiceMaxPBIntegrationGlobal.ProcessFile(caseIdSetforGlobal);
}
update scope;
}
}
答案 0 :(得分:0)
如果批处理作业运行了不止一次,则意味着它已从其他地方调用。
强调某些可能性: