+ Start a Discussion
iyappan kandasamy 4iyappan kandasamy 4 

From child to parent soql query

From child-Parent soql
----------------------------
Parent = college
child =student(lookup with parent)
relation =Students

written query as

for(Student__c s:[select Name,college__r.Name,CollegeName__c from student__c])
{
  system.debug('student Name:'+s.Name+'     college Name:'+s.college__r.Name);
}

but error as

Line: 3, Column: 18
select Name,college__r.Name,CollegeName__c from ^ ERROR at Row:1:Column:13 Didn't understand relationship 'college__r'
Best Answer chosen by iyappan kandasamy 4
Amit Chaudhary 8Amit Chaudhary 8
Try like below

for(Student__c s:[select Name,collegeName__r.Name,CollegeName__c from student__c])
{
  system.debug('student Name:'+s.Name+'     college Name:'+s.collegeName__r.Name);
}

Let us know if this will help you.

Issue was your API name.
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please click on College field (Lookup Field) on Student object . And share the screen shot with child relationship Name.
Prashant Pandey07Prashant Pandey07
+for Amit,Please check the right API name of lookup field on the Student object..

--
Thanks,
Prashant
iyappan kandasamy 4iyappan kandasamy 4
User-added image
Prashant Pandey07Prashant Pandey07
you need to use collegeName__r.Name


--
Thanks,
Prashant
Amit Chaudhary 8Amit Chaudhary 8
Try like below

for(Student__c s:[select Name,collegeName__r.Name,CollegeName__c from student__c])
{
  system.debug('student Name:'+s.Name+'     college Name:'+s.collegeName__r.Name);
}

Let us know if this will help you.

Issue was your API name.
 
This was selected as the best answer
iyappan kandasamy 4iyappan kandasamy 4
Really thanks a lot...It is working fine as per your directions ...thanks again Amit .....thanks a lot