Find your content:

Search form

You are here

IF(Contains) in Apex class


    //Some code here

if temp.items__c size is 2 & addvalue[i].payment__c size is 1, then getting this error

System.ListException: List index out of bounds: 1

Apart from that it works fine.How should I get rid of this problem

Attribution to: Eagerin Sf

Possible Suggestion/Solution #1

This is most likely due to arrays starting on index 0,

for example if you take your array addvalue[], and you add 3 items A, B and C, say you wanted to get the first value (A) you would have to do addvalue[0], either let your loop start from 0, or have it do addvalue[i-1]

if not, I would suggest debugging your arrays and see if all the expected values are correctly filled in.

Attribution to: pjcarly

Possible Suggestion/Solution #2

Are you absolutely sure there are n=temp.size() items in addvallue ?

It may make more sense to store payment__C objects in map and verify if this map contains an item by key of your temp[i].ID

Attribution to: Samuel De Rycke
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content