0

I am writing two queries, and I am having problems getting this right. I have the following set up:

Opportunity

Policy__c Source_Opportunity__c (Lookup to Opportunity)

Policy_Coverage__c

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)

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?

0

Based on your new code, I would propose the following solution...

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 Id IN 
       (SELECT Section_Address__c FROM Section_Address_Link__c WHERE Id = :mapSectionAddressLink.keySet())
    ]);
2
  • Thank you, I have already updated the code now. I have updated the description with what is not working now.
    – Lily
    Dec 17 '14 at 16:02
  • I edited the code to help solve your issue. Let me know if that doesn't work. Thanks,
    – BradByte
    Dec 17 '14 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.