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
sumanth v 18sumanth v 18 

Inner query issue

Opportunity opp = [select id,(select id,Test__c,Name,from Vendor_Groups__r) from opportunity where id =: oppid];

system.debug('@@@@Check1'+opp.Vendor_Groups__r);   No compile error
system.debug('@@@@Check1'+opp.Vendor_Groups__r.
Test__c);   Compile error as shown below
Error: Compile Error: A non foreign key field cannot be referenced in a path expression: Vendor_Groups__r
 
sfdcMonkey.comsfdcMonkey.com
you got this error because 1 opportunity can have multiple child records so you can't direct access the Test__c field in List of Vendor_Group__c
to access
Opportunity opp = [select id,(select id,Name,Test__c from Vendor_Groups__r) from opportunity where id =: oppid];
system.debug('@@@@Check1'+ opp.Vendor_Groups__r);   
system.debug('@@@@Check1'+ opp.Vendor_Groups__r[0].Test__c);

OR play a for loop on Vendor_Group__c

for(Vendor_Group__c  vg : opp.Vendor_Groups__r){
system.debug('@@@@Check1'+ vg.Test__c);
}

i hope it helps you.
  kindly Let me inform if it helps you and close your query by choosing best answer if you got your right answer so it can helps others
thanks
sfdcmonkey.com
Shubham saini 14Shubham saini 14

Hello,

 

Opportunity opp = [select id, Vendor_Groups__r.id, Vendor_Groups__r.Name,Vendor_Groups__r.Test__c from opportunity where id =: oppid];

Thank You