top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Can someone explain how to write a SOQL query to get child custom object?

+2 votes
396 views

I am a beginner. Can someone explain how to write a SOQL query to get child custom object when parent information is given and vice versa?
//student__c - child object, college__c-parent object, Related through Master detail

posted Mar 13, 2016 by Shivam Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Query parent-to-child, which are almost always one-to-many. Specify these relationships using a subquery (enclosed in parentheses), where the initial member of the FROM clause in the subquery is related to the initial member of the outer query FROM clause. Note that for subqueries, you should specify the plural name of the object as that is the name of the relationship for each object.

SELECT Name, ( SELECT LastName FROM Contacts WHERE CreatedBy.Alias = 'x') FROM Account WHERE Industry = 'media'

Query child-to-parent relationships, which are often many-to-one. Specify these relationships directly in the SELECT, FROM, or WHERE clauses using the dot (.) operator.

SELECT Id, Name, Account.Name FROM Contact WHERE Account.Industry = 'media'

answer Mar 14, 2016 by Manikandan J
Similar Questions
+2 votes

I have one parent "quote__c" and child object "Quote_line_item__c" .I want get the parent id with query some thing like this

select id,(select name from quote_line_item__c where name='123' and name='456') from quote__c
...