Relationship field contains at least 2 Objects i.e a Child Object and a Parent Object. These queries are used to fetch Data either from the…
List<Contact> conList = [SELECT firstName, lastName, Email, Account.Name, Account.NumberOfEmployees FROM Contact];Here firstName, lastName, Email are the field of the Contact object while Name and NumberOfEmployee are the fields of the Account objects. So to fetch the field of the Parent object we use the DOT NOTATION Method with the help of the parent object reference which is the Relationship Field name on the Child object. Here Account is Not the Parent Object Name but the Relationship Field Name which is on the Child Object.
List<Leave_Request__c> lrList = [SELECT Name, Leave_Status__c, Consultant__r.Name, Consultant__r.Consultant_Email__c, Consultant__r.Type__c, ];Here Name, Leave_Status__c is the field of the Leave_Request object while Name, Consultant_Email__c, and Type__c are the field of the Consultant object. Check out an amazing Salesforce video tutorial here: Parent to Child SOQL vs Map | Salesforce Training in Apex So to fetch the field of the Parent object we use the DOT NOTATION Method with the help of the parent object reference which is the Relationship Field name on the Child object. Here Consultant__r is Not the Parent Object Name but the Relationship Field Name which is on the Child Object. Note:- In Custom Object, reference field name must be written with suffix __r after Reference Field Name while in Standard Object simply use the Reference Field Name. Reference: shreysharma
There was a problem reporting this post.
Please confirm you want to block this member.
You will no longer be able to:
Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.