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
monkeykingmonkeyking 

Null exception : System.ListException: List index out of bounds: 0

Hello All,

Below is my code,

List<Case> localemailaddress = new List<Case>([SELECT ID,AV_Local_Affiliate_Inbox__c FROM Case Where Id IN : newCaseMap.keySet()]);
if(localemailaddress.size()>0){
                String email=String.valueOf(localemailaddress.get(0));
                    system.debug('Raj debug' +email);
                 OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address =:email];


Eventhough i checked for Null case exception. I am gettingSystem.ListException: List index out of bounds: 0 this erroe.

Can anyone please tell me why ?
Urgent !!

Thanks in advance.
Sridhar NarayansaSridhar Narayansa
In the line "String email=String.valueOf(localemailaddress.get(0));" you are getting a list at index 0 and trying to assign this to a String. This will not work.

Try this
String email=String.valueOf(localemailaddress.get(0).AV_Local_Affiliate_Inbox__c);

Also, I am not sure why you are hardcoding the index value of "0" but I would iterate through the list because you will have more than one record returned in the query. Plus this bulkifies.

Hope if works out.

Thanks,
Sridhar
 
monkeykingmonkeyking
Thank you for your eply Sridhar. NewCasemap will be containing only one id.
That is why i am using this.