+ Start a Discussion
Rohini Sirigiri 5Rohini Sirigiri 5 

Im getting an empty list as a output. It supposed to show the list. List<Candidate__c> candList=[Select id,name,City__c,(select Position__c,Status__c from Job_Applications__r) from Candidate__c Where Name='Shaun smith']; System.debug('List is' +candList);

Im getting the Error : System.ListException: List index out of bounds: 0
Candidate__c(Master object) and Job_Application__c(child object). 
I want to fetch child records.

List<Candidate__c> candList=[Select id,name,City__c, (select Position__c,Status__c from Job_Applications__r) from Candidate__c Where Name='Shaun smith'];
System.debug('List is' +candList);
List<Job_Application__c> jobList=candList[0].Job_Applications__r;
System.debug('List of job are' +jobList);

Please help with this.

 
Best Answer chosen by Rohini Sirigiri 5
Foram Rana RForam Rana R
Hi Rohini,

I hope you are doing well .....!!
I have to Execute your code.
There are a few things that you need to check :
Can you please check the below attachment?


If Name is Auto number then change it to Text Then You got the result



If Name Datatype is AutoNumber then you need to change it from AutoNumber to text you got the result.
Let me know your review.
 
Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.

Thanks & Regards,
Foram Rana

All Answers

vijay kumar kvijay kumar k
Hi Rohini

List index out of bounds:0 is most common error regularly facing every one. So we should be very active on queries.
For you check two three times clearly as you given filter condition is correct or not.
1. For testing your query , 1st query only candidates with putting where condition name='---'. And check really record is coming or if records or coming then 2nd query for job applications, query only job application records putting candidate id with hard code (copy the id from above query)
If job applications are also coming definitely you are query will work fine.
2. Better check child relationship name of job application at candidate leavel.

For knowing child relationship name go to relationship field find child name.

Hope you this is useful to you

Regards
Vijay
Foram Rana RForam Rana R
Hi Rohini,

I hope you are doing well .....!!
I have to Execute your code.
There are a few things that you need to check :
Can you please check the below attachment?


If Name is Auto number then change it to Text Then You got the result



If Name Datatype is AutoNumber then you need to change it from AutoNumber to text you got the result.
Let me know your review.
 
Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.

Thanks & Regards,
Foram Rana
This was selected as the best answer
Rohini Sirigiri 5Rohini Sirigiri 5
Hi Rana,

I just changed from Autonumber to Text. It got solved for me. 
 
Thank you Vijay and Rana for your helpful advice.