I have an apex trigger that involves querying multiple objects. But I encounter this kind of error :
Error: Compile Error: A non foreign key field cannot be referenced in a path expression: ObjectBs__r
Here's a portion of the trigger where I encounter such error message:
Set<Id> objAid = new Set<Id>();
Set<Id> objDid = new Set<Id>();
for(ObjectC__c c : Trigger.new) {
objAid.add(c.ObjectA__c);
}
List<ObjectA__c> objAList = [SELECT Id, Name, (SELECT Id, Name, ObjectD__c FROM ObjectBs__r) FROM ObjectA__c WHERE Id IN: objAid];
for(ObjectA__c a : objAList[0].ObjectBs__r) {
objDid.add(a.ObjectBs__r.ObjectD__c);
}
ObjectB__c
have a relationship (master-detail, or lookup) toObjectA__c
? If it does, are you certain thatObjectBs__r
is the correct child relationship name? (you can check by going to the detail page for the relationship field and looking for "child relationship name")