+ Start a Discussion
jls_74_txjls_74_tx 

Complex WHERE Statement to Exclude IDs

Objects: Map_Point__c.Map_Customer_Notes__r
I want to be able to create a record in Map_Customer_Notes__c with the Type__c 'Exclude' and the ID will omitted from the Map Point results. These are the two otions I've tried and can't get to work.

Thank you so much for your insight and help.

    public list<Map_Point__c> getOption1()
    {
        points = [select ID, NAME, (SELECT ID FROM Map_Point__c.Map_Customer_Notes__r WHERE Type__c = 'Exclude') FROM Map_Point__c WHERE ID NOT IN (SELECT ID FROM Map_Point__c.Map_Customer_Notes__r WHERE Type__c = 'Exclude')];
        return points;
    }


    public List<Map_Point__c> getOption2() {

        List<Id> ExcludeIDs = new List<Id>();
        for (Summary sum : [SELECT ID FROM Map_Point__c.Map_Customer_Notes__r WHERE Type__c = 'Exclude']) {
          ExcludeIDs.add(sum.excludeid);
         }

        List<Map_Point__c> points = [SELECT Id, Name FROM Map_Point__c WHERE ID NOT IN :ExcludeIDs];
        return points;
    }