0

I am getting below error and not sure how to fix that ?

List<Case> csList = [Select Id,OwnerId, (select Id, OwnerId, CreatedById from Payment__r), 
                     (select Id,OwnerId,CreatedById from Payment_2__r) 
                     FROM Case 
                     WHERE Id IN ('XXXXX')];
System.debug('------------------------------------@@ : '+csList); 

for(Case c : csList){
    List<Payment__c> siList = csList[0].Payment__r;
    System.debug('======= '+siList);
    List<Payment_2__c> siList2 = csList[1].Payment_2__r;
    System.debug('======== '+siList2);
}

Getting below error:

System.ListException: List index out of bounds: 1

3

Don't index in unless you are sure there are adequate members in the collection. If it were empty, you would be getting the 0 index out of bounds instead. Make sure you check the size.

List<Payment__c> collection1, collection2;
if (csList.size() > 0) collection1 = csList[0];
if (csList.size() > 1) collection1 = csList[1];
  • Boolean isinfo1Present = c.Payment__r.size() > 0; Boolean isinfo2Present = c.Payment_2__r.size() > 0; I am already checking below... but still not working – Kanika Jan 31 '18 at 16:55
  • If you're checking that, it is not reflected in your question. – Adrian Larson Jan 31 '18 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.