如何处理 Apex 批处理中的 SerialBatchApexRangeChunkHandler 内部 Salesforce.com 错误
How to handle SerialBatchApexRangeChunkHandler Internal Salesforce.com Error in Apex Batch
我正在批量更新几条账户记录。但是,每当更新由于某些验证逻辑而失败时(在此示例中,数字太长),批处理就会陷入处理模式,我必须手动中止它。在日志中我看到 Operation:SerialBatchApexRangeChunkHandler Status:Internal Salesforce.com 错误。如果我删除 Database.Stateful 然后批处理完成,但我需要电子邮件中的错误详细信息,所以我必须实现它。
请帮助我,如果需要更多详细信息,请告诉我。
global class testBatchSettingsAndDebug implements Database.Batchable<sobject>, Database.Stateful {
global String[] email= new String[] {'email@domain.com'};
global List<Database.saveResult> dsrs = new List<Database.saveResult>();
global String errorMessages {get; set;}
global integer count=0;
global List<String> exception_List;
global testBatchSettingsAndDebug (){
errorMessages ='';
}
//Start
global Database.QueryLocator start (Database.BatchableContext bc){
return Database.getQueryLocator('select id from Account limit 10');
}
//Excecute
global void execute (Database.BatchableContext bc, List<sobject> scope){
List<Account > accToUpdateLsit = new List<Account >();//List to hold accs to update
for (sObject objScope: scope) {
Account accObj = (Account )objScope ;//type casting from generic sOject to acc
accObj.NumberofLocations__c= 123456;
accToUpdateLsit.add(accObj);
}
count=accToUpdateLsit.size();
System.debug('Number of Records to update: '+accToUpdateLsit.size());
if (accToUpdateLsit != null && accToUpdateLsit.size()>0) {//Check if List is empty or not
dsrs = Database.update(accToUpdateLsit, false);
System.debug('Records are successfully updated '+accToUpdateLsit);//Update the Records
}
for(Database.SaveResult dsr : dsrs){
if(!dsr.isSuccess()){
errorMessages += string.valueof(dsr.geterrors() + '\n');
}
}
system.debug('Error occured: '+errorMessages);
}
//Finish
global void finish (Database.BatchableContext BC){
System.debug('**Record Updated**'+count);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//Below code will fetch the job Id
AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id
System.debug('Jobid is'+BC.getJobId());
//below code will send an email to User about the status
mail.setToAddresses(email);
mail.setReplyTo('email@domain.com');//Add here your email address
mail.setSenderDisplayName('Account Batch Notification');
mail.setSubject('Account Batch Batch Processing '+a.Status);
mail.setPlainTextBody('The Batch Apex job processed: '+a.TotalJobItems+' batches with: '+a.NumberOfErrors+' failures: '+' Error Messages:'+errorMessages );
Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
System.debug('**Job completed**');
}
}
看来你可以做工作中提到的事情,比如:
声明你的 Database.saveResult 为 transient
我正在批量更新几条账户记录。但是,每当更新由于某些验证逻辑而失败时(在此示例中,数字太长),批处理就会陷入处理模式,我必须手动中止它。在日志中我看到 Operation:SerialBatchApexRangeChunkHandler Status:Internal Salesforce.com 错误。如果我删除 Database.Stateful 然后批处理完成,但我需要电子邮件中的错误详细信息,所以我必须实现它。
请帮助我,如果需要更多详细信息,请告诉我。
global class testBatchSettingsAndDebug implements Database.Batchable<sobject>, Database.Stateful {
global String[] email= new String[] {'email@domain.com'};
global List<Database.saveResult> dsrs = new List<Database.saveResult>();
global String errorMessages {get; set;}
global integer count=0;
global List<String> exception_List;
global testBatchSettingsAndDebug (){
errorMessages ='';
}
//Start
global Database.QueryLocator start (Database.BatchableContext bc){
return Database.getQueryLocator('select id from Account limit 10');
}
//Excecute
global void execute (Database.BatchableContext bc, List<sobject> scope){
List<Account > accToUpdateLsit = new List<Account >();//List to hold accs to update
for (sObject objScope: scope) {
Account accObj = (Account )objScope ;//type casting from generic sOject to acc
accObj.NumberofLocations__c= 123456;
accToUpdateLsit.add(accObj);
}
count=accToUpdateLsit.size();
System.debug('Number of Records to update: '+accToUpdateLsit.size());
if (accToUpdateLsit != null && accToUpdateLsit.size()>0) {//Check if List is empty or not
dsrs = Database.update(accToUpdateLsit, false);
System.debug('Records are successfully updated '+accToUpdateLsit);//Update the Records
}
for(Database.SaveResult dsr : dsrs){
if(!dsr.isSuccess()){
errorMessages += string.valueof(dsr.geterrors() + '\n');
}
}
system.debug('Error occured: '+errorMessages);
}
//Finish
global void finish (Database.BatchableContext BC){
System.debug('**Record Updated**'+count);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//Below code will fetch the job Id
AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id
System.debug('Jobid is'+BC.getJobId());
//below code will send an email to User about the status
mail.setToAddresses(email);
mail.setReplyTo('email@domain.com');//Add here your email address
mail.setSenderDisplayName('Account Batch Notification');
mail.setSubject('Account Batch Batch Processing '+a.Status);
mail.setPlainTextBody('The Batch Apex job processed: '+a.TotalJobItems+' batches with: '+a.NumberOfErrors+' failures: '+' Error Messages:'+errorMessages );
Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
System.debug('**Job completed**');
}
}
看来你可以做工作中提到的事情,比如: 声明你的 Database.saveResult 为 transient