function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan 

Ending Position out of bound : -1 error facing in batch apex process why?

Hi All, 

I have the following error showing in the apex jobs that I was runnig in to the batch process. But the status shows as completed. I need to know what might be the issues was. I do not use any substring in this batch class and I have only the list collection and updating the lists.
 

2/28/2018 1:00 AM
Batch ApexCompletedFirst error: Ending position out of bounds: -11,5111,5110Persson, Philip2/28/2018 2:21 AMAccountUpdateWithStuCollecBatch_AC
 
Any help would be greatly appreciated!
 
Best Answer chosen by Kamatchi Devi Sargunanathan
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Hi All,

Finally I found the exact problem here.

Atually I have been receiving this error while the dot in indexOf string method. Because while checking dot or any special characters we should be careful on using direct character to check like this indexOf('.'). Since in some place it could results in -1 that if the special charater is not found. 

So, I have changed this usgin split as shown below and this will never get in to trouble,
String env =  'testttgrp--Test1.cs19.my.salesforce.com' ;

String[] splitVal = env.split('\\.');  //This is where the logic works

if(splitVal.size() > 0){
    env = splitVal[0];
}
This will give the result as expected and there would not be any issues for batch job with -1 exception.

Thanks,
Kamatchi Devi Sargunanathan
 

All Answers

Karthik KKarthik K
Very likely the list is blank or the index # is not available of the list.
Say for instance, if the size of the list is 1 and  trying to access the index of 2. 
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Hi Karthik, 

Sure thanks for the sugesstions, I am also working on the logs to identify the exact Issue might be bacause of the list.
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Hi All, 

Really its getting interesting to analyse this issue!

I found some log today related to this error and following are the lines where am getting the error,
String env =  'testttgrp--Test1.cs19.my.salesforce.com' ;
env = env.substring(0,env.indexOf('.'));
system.debug('index number====>'+env.indexOf('.'));
system.debug('env====>'+env);
I tried to run the above code in Developer console in anonymous window and found the following output,
  • index number====> -1
  • env====> testttgrp--Test1
I still confused why this is happening, If anyone found the answer please let me know.
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan
Hi All,

Finally I found the exact problem here.

Atually I have been receiving this error while the dot in indexOf string method. Because while checking dot or any special characters we should be careful on using direct character to check like this indexOf('.'). Since in some place it could results in -1 that if the special charater is not found. 

So, I have changed this usgin split as shown below and this will never get in to trouble,
String env =  'testttgrp--Test1.cs19.my.salesforce.com' ;

String[] splitVal = env.split('\\.');  //This is where the logic works

if(splitVal.size() > 0){
    env = splitVal[0];
}
This will give the result as expected and there would not be any issues for batch job with -1 exception.

Thanks,
Kamatchi Devi Sargunanathan
 
This was selected as the best answer