function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chubsubchubsub 

Apex Trigger Help

Hello, I'm getting to following error message, any ideas? Thanks in advance!

 

System.ListException: List index out of bounds: 0: Class.ManageOpportunitiesBeforeUpdate.beforeUpdate: line 84, column 32

 

list<Opportunity> allopps = [select Id, AccountId, CreatedDate
from Opportunity
where Id in :accids
and CreatedDate in :createdDates
order by AccountId, CreatedDate];
map<Id, Integer> oppid2seqnummap = new map<Id, Integer>();

//reset placeholders: last Account, last Date, current counter
Id thisaccid = allopps[0].AccountId;
Date thisdate = allopps[0].CreatedDate.date();
Integer counter = 0;

 

 

Best Answer chosen by Admin (Salesforce Developers) 
rvkrvk

Before getting  the value from list check the size of the list. 

 

Id thisaccid;

Date thisdate

list<Opportunity> allopps = [select Id, AccountId, CreatedDate
from Opportunity
where Id in :accids
and CreatedDate in :createdDates
order by AccountId, CreatedDate];
map<Id, Integer> oppid2seqnummap = new map<Id, Integer>();

//reset placeholders: last Account, last Date, current counter

if(allopps.size()>0){
 thisaccid = allopps[0].AccountId;
thisdate = allopps[0].CreatedDate.date();

}
Integer counter = 0;