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

Index Out of bounds
I have an object that is filled from fields from another object. I created a list of the same object type and I need to add the records to it. However it is giving me the Index out of bounds error when I add the record to the list. Here follows the code:
Line__c MELI = new Line__c();
List<Line__c> LMELI = new List<Line__c>();
List<TX__c> Trx = [SELECT Id, Amount__c
FROM TX__c
integer i = 0;
for (TX__c PMT : Trx) {
MELI.MB__c = Ref__c;
MELI.Tx__c = PMT.Id;
MELI.Amount__c = PMT.Amount__c;
LMELI.add(i++, MELI); // The error is on this line
} // for PMT ends here
I would greatly appreciate any help!
Thank you!
Line__c MELI = new Line__c();
List<Line__c> LMELI = new List<Line__c>();
List<TX__c> Trx = [SELECT Id, Amount__c
FROM TX__c
integer i = 0;
for (TX__c PMT : Trx) {
MELI.MB__c = Ref__c;
MELI.Tx__c = PMT.Id;
MELI.Amount__c = PMT.Amount__c;
LMELI.add(i++, MELI); // The error is on this line
} // for PMT ends here
I would greatly appreciate any help!
Thank you!
Line__c MELI = new Line__c();
Map<Line__c> LMELI = new Map<Integer, Line__c>();
List<TX__c> Trx = [SELECT Id, Amount__c
FROM TX__c
integer i = 0;
for (TX__c PMT : Trx) {
MELI.MB__c = Ref__c;
MELI.Tx__c = PMT.Id;
MELI.Amount__c = PMT.Amount__c;
LMELI.put(i++, MELI); // The error is on this line
} // for PMT ends here