+ Start a Discussion
Vigneshwaran LoganathanVigneshwaran Loganathan 

didn't understand the relationship

Hi.
I have two custom objects Our_va__c and Cancellation__c. cancellation has Lookup to Our VA.

I need to fetch all cancellation records for the purticular Our va. I have written query like..
 
///***** Cosider All our_va__c ids are in Ovaids

List<our__va__c> ova= new list<our_va__c>();

ova=[select id,name, (select name from cancellation__r) from our_va__c where id IN : Ovaids]

I got the error didn't Understand the relationship...

Anyone help plz??
Best Answer chosen by Vigneshwaran Loganathan
Vijaya Kumar RegantiVijaya Kumar Reganti
Hi,

use cancellations__r instead if cancellation__r inside the inner query

or do something like this.
 
list<child__c> childList = [select id from child__c where id where Id =: parentId];


Thanks,
Vijay

All Answers

Vivek DeshmaneVivek Deshmane
Hi ,
You have look of Cancellation__c on Our VA then Our VA will have only on Cancellation__c  associated with it.
Query should be looks like below.
List<our__va__c> ova= new list<our_va__c>();

ova=[select id,name,  cancellation__r.name from our_va__c where id IN : Ovaids]

//If you cancellation IDS list then

List< cancellation__c> lstCan=[Select nam,(Select id,name FROM ourva__r ) FROM cancellation__c WHERE id IN: lstCancelIDs];

Please let me know if it helps you.
Best Regards,
-Vivek
 
Vijaya Kumar RegantiVijaya Kumar Reganti
Hi,

use cancellations__r instead if cancellation__r inside the inner query

or do something like this.
 
list<child__c> childList = [select id from child__c where id where Id =: parentId];


Thanks,
Vijay
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
"__r" is used for retrieving field values from the object's related another object when those objects have relationship via Lookup field.
See links below for detail and samples

__r represents a custom relationship. There are two uses for __r. We use it when we query a custom relationship from child to parent, or from parent to child.
Please check below post for more example 
http://salesforce.stackexchange.com/questions/28708/difference-between-c-and-r

UNDERSTANDING RELATIONSHIPS IN SALESFORCE
http://www.forcetree.com/2009/07/understanding-relationships-in.html



Please check below blog with screen shot. I hope that will help u 
http://11concepts.com/sfdc/blog/understanding-__c-and-__r/


Please let us know if this will help you

Thanks
Amit Chaudhary