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
jaysree Ajaysree A 

how to write a soql query for parent to child

parent is custom object and child is standard object(lookup relationship)
Adam OlshanskyAdam Olshansky
This Trailhead module gives a great example! https://developer.salesforce.com/trailhead/microsoft_dotnet/database_basics_dotnet/sql_to_soql

Basically you'll just include it as a field (SELECT ID, Name, CustomField__c, (SELECT ID, Name FROM StandardObjects) FROM MyCustomObject__c).  Make sure it is plural as well and then you can reference it by saying something like List<StandardObject> = customObj.StandardObjects
JyothsnaJyothsna (Salesforce Developers) 
Hi Jaysree,

Please check the below sample code. The below sample code display Account related contacts. Please try to check this code in the anonymous block.

 
List<account> acclst=[select id, name , (select Lastname from contacts) from Account ];
 Please refer the below link for more details.

http://example! https://developer.salesforce.com/trailhead/microsoft_dotnet/database_basics_dotnet/sql_to_soql

​Hope this helps you!
Best Regards,
Jyothsna
DeepthiDeepthi (Salesforce Developers) 
Hi Jaysree,

I have a created a LookUp relationship between Vehicle__c (Parent custom object) and Opportunity(child standard object). Check the SOQL as an example to your requirement.
 
select id,CustomField__c,(select id,Amount from Opportunities__r ) from Vehicle__c

Please note "Opportunities" is the child relationship name.
Let me know if need any help!

Best Regards,
Deepthi