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
RAMANJINEYULU GOGULARAMANJINEYULU GOGULA 

Regarding dot notation

How can I retrieve object records using dot notation?
Please specify with examples for some standard or custom objects.
Best Answer chosen by RAMANJINEYULU GOGULA
DeepthiDeepthi (Salesforce Developers) 
Hi Ramanjineyulu,

The Dot notation simply lets you traverse objects through relationships and fields.
Example: Custom objects can also participate in relationship queries where Daughter__c(child object) and Mother__c(parent object).
  • When you use a child-to-parent relationship, you can use dot notation: 
 
SELECT Id, FirstName__c, Mother_of_Child__r.FirstName__c
FROM Daughter__c
WHERE Mother_of_Child__r.LastName__c LIKE 'C%'
      where Mother_of_Child__c is the lookup field name
  • Parent-to-child relationship queries do not use dot notation:
SELECT LastName__c,
  (
    SELECT LastName__c
    FROM Daughters__r
  )
FROM Mother__c

Example: When we take the case of standard objects.
  • Parent to Child Query
SELECT Account.Name,(SELECT Contact.Name FROM contacts) FROM Account
  • Child to Parent Query
select Account.id, Account.Name from Contact

Also check the below links for reference:

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

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

http://developer.force.com/cookbook/recipe/using-relationship-queries

Hope this helps you!
Best Regards,
Deepthi

All Answers

DeepthiDeepthi (Salesforce Developers) 
Hi Ramanjineyulu,

The Dot notation simply lets you traverse objects through relationships and fields.
Example: Custom objects can also participate in relationship queries where Daughter__c(child object) and Mother__c(parent object).
  • When you use a child-to-parent relationship, you can use dot notation: 
 
SELECT Id, FirstName__c, Mother_of_Child__r.FirstName__c
FROM Daughter__c
WHERE Mother_of_Child__r.LastName__c LIKE 'C%'
      where Mother_of_Child__c is the lookup field name
  • Parent-to-child relationship queries do not use dot notation:
SELECT LastName__c,
  (
    SELECT LastName__c
    FROM Daughters__r
  )
FROM Mother__c

Example: When we take the case of standard objects.
  • Parent to Child Query
SELECT Account.Name,(SELECT Contact.Name FROM contacts) FROM Account
  • Child to Parent Query
select Account.id, Account.Name from Contact

Also check the below links for reference:

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

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

http://developer.force.com/cookbook/recipe/using-relationship-queries

Hope this helps you!
Best Regards,
Deepthi

This was selected as the best answer