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
sreejasreeja 

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 

  thanks  
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

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.

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm


http://www.sfdc99.com/2013/06/09/example-how-to-write-a-cross-object-soql-query/

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];
OR
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