Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

    //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

share|improve this question

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! – pjcarly 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.