You need to sign in to do that
Don't have an account?
Deepak Singh 116
First error: List index out of bounds: 34
Hi ,
I have written the following batch which update the description from o field CurrentGenerators__c both the fields are on opportunity but when i execute this batch i get the error First error: List index out of bounds: 34.
Please help.
global with sharing class errorinBatch implements Database.Batchable<SObject>,Database.stateful {
global set <String> log;
global database.QueryLocator start(Database.BatchableContext bc){
string query='select id,name,Description,CurrentGenerators__c from opportunity';
system.debug(database.getQueryLocator(query));
return database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<SObject> scope){
System.debug(scope);
System.debug('====>>>>>'+scope.size());
//List<Opportunity> opp=new List<Opportunity>();
if(scope.size()>0){
for(Opportunity op:(List<Opportunity>)scope){
System.debug(op.Name);
op.Description=op.CurrentGenerators__c;
// opp.add(op);
}
}
database.SaveResult[] result=database.update(scope,false);
System.debug('====>Result'+result);
Integer rsize=result.size();
for(integer i=0;i<=rsize;i++){
System.debug('for loop Block');
System.debug('====>Result[0]'+result[0]);
System.debug('=====>'+i);
System.debug('+++++>>'+scope[i].Id);
if(!result[i].isSuccess()){
log=new Set<String>();
log.add('Error in Opportunity'+scope[i].Id+'Error Message'+result[i].getErrors()[0].getMessage());
System.debug(log);
}
else {
system.debug('+++++>>> updated successfully');
}
}
}
global void Finish(Database.BatchableContext bc){
//System.debug(log);
}
}
I have written the following batch which update the description from o field CurrentGenerators__c both the fields are on opportunity but when i execute this batch i get the error First error: List index out of bounds: 34.
Please help.
global with sharing class errorinBatch implements Database.Batchable<SObject>,Database.stateful {
global set <String> log;
global database.QueryLocator start(Database.BatchableContext bc){
string query='select id,name,Description,CurrentGenerators__c from opportunity';
system.debug(database.getQueryLocator(query));
return database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<SObject> scope){
System.debug(scope);
System.debug('====>>>>>'+scope.size());
//List<Opportunity> opp=new List<Opportunity>();
if(scope.size()>0){
for(Opportunity op:(List<Opportunity>)scope){
System.debug(op.Name);
op.Description=op.CurrentGenerators__c;
// opp.add(op);
}
}
database.SaveResult[] result=database.update(scope,false);
System.debug('====>Result'+result);
Integer rsize=result.size();
for(integer i=0;i<=rsize;i++){
System.debug('for loop Block');
System.debug('====>Result[0]'+result[0]);
System.debug('=====>'+i);
System.debug('+++++>>'+scope[i].Id);
if(!result[i].isSuccess()){
log=new Set<String>();
log.add('Error in Opportunity'+scope[i].Id+'Error Message'+result[i].getErrors()[0].getMessage());
System.debug(log);
}
else {
system.debug('+++++>>> updated successfully');
}
}
}
global void Finish(Database.BatchableContext bc){
//System.debug(log);
}
}
You just remove '=' Singh from this line:
for(integer i = 0 ; i <= rsize ; i++)
that will become
for(integer i = 0 ; i < rsize ; i++)
Try this code: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
All Answers
You just remove '=' Singh from this line:
for(integer i = 0 ; i <= rsize ; i++)
that will become
for(integer i = 0 ; i < rsize ; i++)
Try this code: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
It works.