0

I'm trying to query based on serveral email address fields, but for some reason I am return ALL contact records in the org. I'm using several IN clauses, but I didn't think it would cause any issues. Can anyone point out whats wrong here?

I return the same number of results( all of them!) regardless of if OrderEmailAddresses contains one item, or 200 items.

    Set<string> OrderEmailAddresses = GetEmailAddressesFromOrders(Orders);//Collects email addresses from incoming orders
    //Get all contacts that match email addresses on incoming orders
    List<Contact> ExistingContacts = [SELECT Id,
                                      npe01__HomeEmail__c,
                                      npe01__AlternateEmail__c,
                                      email,
                                      npe01__WorkEmail__c,
                                      Alternate_Email_2__c,
                                      Alternate_Email_3__c
                                      FROM Contact WHERE 
                                      npe01__HomeEmail__c IN :OrderEmailAddresses OR
                                      npe01__AlternateEmail__c IN :OrderEmailAddresses OR
                                      email IN :OrderEmailAddresses OR
                                      Alternate_Email_2__c IN :OrderEmailAddresses OR
                                      Alternate_Email_3__c IN :OrderEmailAddresses OR
                                      npe01__WorkEmail__c IN :OrderEmailAddresses
                                      ORDER BY LastModifiedDate DESC];
2
  • 2
    Does the Set contain a blank or null as one of the values? If so, then it would probably give you everything. Dec 5, 2014 at 6:54
  • You are correct. I iterated the list right after I posted it and that's what the problem was. Make it an answer and I'll credit you. Thanks! Dec 5, 2014 at 6:57

2 Answers 2

2

If your Set of email addresses contains a blank or null value then it would return most contact records since most of the Contacts probably have at least one of those filtered fields empty.

1

I think the issue could be a Null value in set. In Set that you created which is returned by a method. Please ensure that value is added in this set only if it is not null.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .