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
farah sheriffarah sherif 

test class help related to code that used to work before but doesn't work now

WHEN i RUN THIS PART OF THE CODE IT GIVES ME THE BELOW ERROR ALTHOUGH IT USED TO WORK BEFORE

 if(a[0].Product_Family__c == '360 Suite'){
            a[0].Status = 'Canceled';
        }
        




error:

System.ListException: List index out of bounds: 0
Best Answer chosen by farah sherif
Deepali KulshresthaDeepali Kulshrestha
Hi Farah,

It looks like you have empty list and you are trying to "Product_Family__c " from the 0 index of empty list. Please make sure you are inserting the records properly on Test class or check the debug logs for any exception while inserting record.
If it doesn't help then please share your code.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
 

All Answers

MiroMiroMiroMiro
Looks like, before processing, you need to check the list check if it "s empty or not. If you try to access a.0] without empty check then it will obviously throw that error!
Nik shNik sh
Hi Farah sherif,

Please check the size of list is empty or not.
https://help.salesforce.com/articleView?id=000181121&type=1

Thank you.
Deepali KulshresthaDeepali Kulshrestha
Hi Farah,

It looks like you have empty list and you are trying to "Product_Family__c " from the 0 index of empty list. Please make sure you are inserting the records properly on Test class or check the debug logs for any exception while inserting record.
If it doesn't help then please share your code.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
 
This was selected as the best answer