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
Julien CampJulien Camp 

List index out of bounds - 0: Error - how to fix?

Hello,

We are receiving an error in relation to a recently deployed Apex Class. 

Here's the error:

"caused by: System.ListException: List index out of bounds: 0
Class.EditClientComplianceCheckList_Controller.<init>: line 25, column 1"

And here is line 25 (and a few subsequent lines):

system.debug('ClientComplianceDocuments_List=='+ClientComplianceDocuments_List[0].Id+' name =='+ClientComplianceDocuments_List[0].Name);
ClientComplianceDocId_ComplianceDoc_Map = new Map<Id,Compliance_Document__c>();
ComplianceDocuments_NewlyAdded_Map = new Map<Compliance_Document__c,Boolean>();


Anyone have any insight?

Thanks!
Julien
Alain CabonAlain Cabon
Hello,

isEmpty() Returns true if the list has zero elements.

if (!ClientComplianceDocuments_List.isEmpty()) {

system.debug('ClientComplianceDocuments_List=='+ClientComplianceDocuments_List[0].Id+' name =='+ClientComplianceDocuments_List[0].Name);

}

System.ListException: List index out of bounds: 0 = The list is empty ( [0] is the first element and it doesn't exist, second element, [1], third, [2] ...)