+ Start a Discussion

child- parent soql with the masterdetail relation ship

i have created a custom objects of  contract__C (parent)and quotatin__C as(child),  and created a masterdetail relation between them ..
 i need to query the parent id as like :

 contact = [select Id,name,accountid from contact where accountid=:selectedAccId];

i hve used :

quotation__c =[select id, name , contract__r.id  form quotation__c where contract_r.id =: selectdContid]; 

how can i call this .. any suggestions 

Khan AnasKhan Anas (Salesforce Developers) 

Greetings to you!

Custom object child relationships end in __r. So the likely relationship name would be Contract__r.  Your query is correct. You can check the field name (lookup or master-detail) by following below steps.
Go to Quotation object -> Fields and Relationships -> Contarct field

You can check your query by executing it in 'Open Execute Anonymous Window'.

Please refer to the below links which might help you further.



I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

Raj VakatiRaj Vakati
Change you Query llike below and you are query is almst looks correct

List<quotation__c> qu =[select id, name , contract__r.id  form quotation__c where contract_r.id =: selectdContid];

Deepali KulshresthaDeepali Kulshrestha
Hi Sree,

You can get id of parent record from the child record  from the  following  queries:

List<quotation__c> qList=[select id, name , contract__c  from quotation__c where contract__c =: selectdContid];
List<quotation__c> qList=[select id, name , contract_r.id  from quotation__c where contract_r.id =: selectdContid];

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha