Relationship queries involve at least two objects, a parent and a child. These queries are used to fetch data either from the Parent object, when SOQL query is written on child, or from child object when SOQL query is written on parent.
SELECT relationship_field.parent_obj_field FROM child_object;
List<Opportunity> oppList = [SELECT name, amount, closeDate, account.name
for(Opportunity o: oppList)
System.debug(‘Opp: ‘ + o.name + ‘ Acc: ‘+o.account.name);
SELECT (relationship_field)__r.parent_obj_field FROM child_object;
List<Branch__c> branchList = [select Branch_ID__c, State__c,
Branch_of_Bank__r.Bank_Name__c from Branch__c];
for(Branch__c bl: branchList)
System.debug(‘Bank Name: ‘+bl.Branch_of_Bank__r.Bank_Name__c
+ ‘Branch: ‘+bl.State__c);
< < Previous
Next > >
The batch is going to start shortly. Fill the form given below to Register yourself now.
Fill the form below to get a demo of this course.
Online Salesforce Development Course is soon going to be launched. Please fill the form and we will notify you about the course.