• rajcrm86
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi All - I'm somewhat familiar with the Non-Selective query problem, however, this one has got me stumpped.  My company has a full sandbox and I have my own development sandbox.  The same piece of code in our Full Sandbox and Production is causing a non-selective query in my dev sandbox.  No issue at all in Full SB or Production.

The query is as follows:  Note that this is in an After Update / After Insert Opportunity Trigger helper class.

for(CampaignMember cm: [SELECT id, ContactId FROM CampaignMember WHERE Campaign.Id =: campaignId])
{
    existingCampMembers.add(cm.ContactId);
}

I have one campaign member on one campaign in my dev sandbox.....that's it!!

If I execute query in developer console it returns the record.  If I execute anonymous, it finds the record no problem.  Also, if I were to change the filter to specify a contactid instead of campaign.id I do not get non-selective error.  So clearly there is something going on with Campaign.Id, but why here and not in Full SB or Production?

So does anyone have any ideas as to why I'm getting a non-selective query in my dev sandbox but not full sb or production?

Thank you in advance for any suggestions.

Jason

Below is the complete error message.

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger OpportunityTrigger caused an unexpected exception, contact your administrator: OpportunityTrigger: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Class.OpportunityTriggerLogic.addCampMbrToBldrPrgm: line 79, column 1
  • May 06, 2014
  • Like
  • 0