You need to sign in to do that
Don't have an account?

Calculations on a list
Hello everyone,
I am trying to do some data manipulation over records in a list. I was able to correctly build my list but now I am stuck with the calculations that I want to see happen.
Let's say I have record 1 and record 2 in my list. I want to grab a field called meter readings on both record and subtract the value of record 2 from the value from record 1 to get the actual energy use.
record 1 energy use = record 1 meter reading - record 2 meter reading.
And obvisouly I would like to repeat that for every records in my list except for the last one (since I would not have a second meter reading to do the calculation).
At first I thought of using a variable to control the for loop but I keep getting the following error message: "System.ListException: List index out of bounds: 15"
I am trying to do some data manipulation over records in a list. I was able to correctly build my list but now I am stuck with the calculations that I want to see happen.
Let's say I have record 1 and record 2 in my list. I want to grab a field called meter readings on both record and subtract the value of record 2 from the value from record 1 to get the actual energy use.
record 1 energy use = record 1 meter reading - record 2 meter reading.
And obvisouly I would like to repeat that for every records in my list except for the last one (since I would not have a second meter reading to do the calculation).
At first I thought of using a variable to control the for loop but I keep getting the following error message: "System.ListException: List index out of bounds: 15"
All Answers
I think this should cover a few scenarios for you, but keep in mind that the code is untested and may require some tweaking (especially since I used made up custom objects to fit the scenario).