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
s9s9 

System.ListException: List index out of bounds: 0: AnonymousBlock: line 8, column 1

Hi

 

In this candidate objects Contains two records with same name like firstname='sg' it through a error

 

System.ListException: List index out of bounds: 0: AnonymousBlock: line 8, column 1

 

LIST<Candidate__c> cl=[SELECT id,name,(SELECT id,Job_Application__c.Status__c,Job_Application__c.Total_Rating__C
                                       FROM Job_Applications__r)
                      FROM Candidate__c where
                      first_name__c='sg'];
for(candidate__c c:cl)
{
                      system.debug(c);
System.debug('The Job Application name is:'+c.Job_Applications__r[0].status__c);
System.debug('The Total Rating is:'+c.Job_Applications__r[0].Total_Rating__c);
}

 

 

 

 

Thanks

digamber.prasaddigamber.prasad

Hi,

 

I assume API name of Job Application object is Job_Application__c. Could you please try below code and it should be running fine. Actually we need to make sure that there is a record in relationship queried.

 

LIST<Candidate__c> cl=[SELECT id,name,(SELECT id,Job_Application__c.Status__c,Job_Application__c.Total_Rating__C
                                       FROM Job_Applications__r)
                      FROM Candidate__c where
                      first_name__c='sg'];
for(candidate__c c:cl)
{
	system.debug(c);
	//I assume API name of job application object is Job_Applications__c
	for(Job_Applications__c jobAppl : c.Job_Applications__r){
		System.debug('The Job Application name is:'+ jobAppl.status__c);
		System.debug('The Total Rating is:'+ jobAppl.Total_Rating__c);
	}
}

Please let me know if it doesn't work for you.

 

Happy to help you! 

s9s9

Thanks Prasad

 

But small change in for loop

 

LIST<Candidate__c> cl=[SELECT id,name,(SELECT id,Job_Application__c.Status__c,Job_Application__c.Total_Rating__C
                                       FROM Job_Applications__r)
                      FROM Candidate__c where
                      first_name__c='sg'];
for(candidate__c c:cl)
{
    system.debug(c);
    //I assume API name of job application object is Job_Applications__c
    for(Job_Application__c jobAppl : c.Job_Applications__r){
        System.debug('The Job Application name is:'+ jobAppl.status__c);
        System.debug('The Total Rating is:'+ jobAppl.Total_Rating__c);
    }
}

 

Thanks

Ramesh

digamber.prasaddigamber.prasad

Cool. Happy that it helped you! If you think that it helped in resolving your issue, please give me KUDO for this and mark it as solution, it will help other to find solution easily.

 

Happy to help you!