Type of SOQL Query in Salesforce

There are two type SOQL Query in Salesforce:-

Child to Parent:-

  • Sometime we want to fetch few fields of the parent record while working with child record then we go for child to parent query.
  • For example, working with contacts records user need the Account Shipping Address then for this use case SOQL will Look like below.
  • SELECT Id, Name, AccountId, Account.ShippingAddress From Contact.
  • In the above SOQL Account is the Field Name for Lookup/Master Details on the Contacts (Child) Object.

Parent to Child (Inner Query):-

Why we use parent to child Inner Query?:-

  • Whenever we want to retrieve the related/child record for particular parent record or set of parent record then use the concept of Inner Query.
  • For example, we want to retrieve the Contacts Related to particular Account then we will use below SOQL.
  • SELECT Id, Name, (Select Id, Name From Contacts ) From Account WHERE Id IN: accList.
  • Here is the above Query Contacts is Relationship Name. For standared Object it will always will be the Plural label of object name. For example, Contact => Contacts, Case = > Cases, Opportunity => Opportunities.
  • For Custom Objects, We will append__r which will represent the Relationship with Account then in the Inner Query it will be Books__r.


To know more live demo source code in Salesforce lightning, Trigger, Visualforce & LWC, Use this link..



Type of SOQL Query in Salesforce Type of SOQL Query in Salesforce Reviewed by Admin on 4:06 AM Rating: 5

8 comments:

header banner -- www.w3web.net



Powered by Blogger.