I am writing two queries, and I am having problems getting this right. I have the following set up:
Policy__c Source_Opportunity__c (Lookup to Opportunity)
Policy__c(Lookup to Policy__c)
Section_Address_Link__c (Junction Object)
Policy_Coverage__c (Lookup to Policy_Coverage__c)
Section_Address__c (Lookup to Section_Address__c)
I need to query from Section Address all the way up to the Source Policy.
NOTE: setCovId is a set of policy coverages.
Map<Id, Section_Address_Link__c> mapSectionAddressLink = new Map<Id, Section_Address_Link__c>( [select Id, Policy_Coverage__r.Policy__r.Source_Opportunity__c FROM Section_Address_Link__c WHERE Policy_Coverage__c in :setCovId] ); Map<Id, Section_Address__c> mapSectionAddress = new Map<Id, Section_Address__c>( [Select Id,(Select Policy_Coverage__r.Policy__r.Source_Opportunity__c FROM Section_Address_Links__r) From Section_Address__c WHERE ?????]
In the first query I say that the Section_Address_Links__c are linked to Policy_Coverage__c. And in my second query, I want to say something similar, i.e. I want to only select those Section_Addresses__c that are linked by Section_Address_Link__c. How would I achieve this?