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
Naresh.soft12Naresh.soft12 

list out of bond exception?

hi can any one share list out of bond exception program and explain?
Nayana KNayana K

Suppose you have List of 5 items (0,1,2,3,4  are valid indexes to access its elemt) and you are trying to get nth index which is not present in the list, then it will throw such error.

Eg : Try this out in dev console.

List<String> lstItem = new List<String>();
lstItem.add('Item1');
lstItem.add('Item2');
lstItem.add('Item3');
lstItem.add('Item4');
lstItem.add('Item5');

// below line works fine
system.debug('====accessing item4===='+lstItem[3]);
//below line throws error
system.debug('====accessing 5th index item which is not present===='+lstItem[5]);
 
sfdcMonkey.comsfdcMonkey.com
hi Naresh
go to this salesforce Knowledge Article for understand this exception
https://help.salesforce.com/apex/HTViewSolution?id=000181121&language=en_US

Thanks 
Please mark it as solved if this helps you so that it will make for others as a proper solution