SOQL Document
SOQL Document
1. Fetch the child record from parent record (Contact is child and Account is Parent) –
Standard Objects
SELECT Id, Name, (SELECT Id, LastName FROM Contacts) FROM Account.
Note- Contacts is a Child Relationship Name which is lookup field in child object
2. Fetch the child record from parent record (Student__c is child and Teacher__c is
Parent) – Custom Objects
SELECT Id, Name, (SELECT Id, Name FROM Students__r) FROM Teacher__c
Note - Students is a Child Relationship Name(appended ‘ __r’ in Students) which is lookup field in
child object
3. Fetch the Parent record from Child Record (Contact is child and Account is Parent) –
Standard Object
4. Fetch the Parent record from Child Record (Student__c is child and Teacher__c is Parent) –
Custom Object
SELECT Id, Name FROM Account WHERE Id NOT IN (SELECT AccountId FROM Contact)
Nripesh Kumar Joshi (Salesforce Developer)
Note- We can not use count with the field that is used in Group By.
For example we can not count name because we are using Name field in Group By
8. Determine how many leads are associated with each LeadSource value
9. Fetch the Lead Record that are associate with each LeadSource that generated more
than 10 times
10. Fetch the Lead record where name end with ‘abc’
*** Group By - GROUP BY is used with Aggregate functions to group the result set by single or
multiple columns.
*** Having - HAVING is an optional clause that can be used in a SOQL query to filter results that
aggregate functions return.
*** WHERE - We can add the condition with the help of WHERE Clause