Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

    //Some code here

if temp.items_c size = 2 & addvalue[i].payment_c size = 1 then getting this error

Visualforce Error System.ListException: List index out of bounds: 1

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

share|improve this question

2 Answers 2

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.

share|improve this answer
here my problem is for the first time it becomes true and when it enters for second time it is showing the error.Went with i-1 but getting the error List index out of bounds: -1 –  Eagerin Sf Dec 17 '12 at 13:13

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

share|improve this answer
Got it.... for(integer i =0; i<temp.size();i++){ if(temp[i].Items__c.contains(addvalue[i].payment__c)){} } ... Here I'm iterating only the temp size.Need to iterate the addvalue size also...something like this for(integer i =0; i<temp.size();i++){ for(integer j =0; j<addvalue.size();j++){ if(temp[i].Items__c.contains(addvalue[j].payment__c)){} } } –  Eagerin Sf Dec 17 '12 at 13:45
are you sure there are the same amount of items in temp and addvalue? that will most likely be your problem! –  PJC Dec 17 '12 at 13:59
Please don't post code in comments, but update your question with it. This makes it more readable, and easier to find (it is relevant!) for other readers. I think it may help if you explain what you want to achieve, versus how you have tried to implement it. So someone can advise on the better approach to code it. –  Samuel De Rycke Dec 17 '12 at 14:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.