+ Start a Discussion
murdocmurdoc 

System.QueryException: Non-Selective Query against large object type

I'm sure this is pretty standard, but we have a major problem as we're in the middle of a deployment. I got this error when trying to deploy this test class: System.QueryException: Non-Selective Query against large object type. Consider an indexed filter. I need to adjust this so I can get this deployed. Any ideas as to how to index this line so I can get it to pass. Any help would be greatly appreciated. Thanks! Below is the portion of code in question.

 Opportunity campOpp = [Select Campaign.Parent.Id, Show_Campaign_ID__c from opportunity where id = :o4.id];
        System.debug('campOpp ->' + campOpp);
      
        System.currentPageReference().getParameters().put('opportunityId', o4.Id);
        List<Opportunity> listOpps = new List<Opportunity>([Select o.AccountId, o.Show_Campaign_ID__c,
        o.Campaign.Show_Close_Date__c, Name, Account_Manager__r.Name, (Select Id,  
        IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp,
        LastActivityDate, ConnectionReceivedId, ConnectionSentId, Opp_Show_Name__c,
        Opp_Owner__c, Opp_Acct_Management_Producing__c, Opp_Acct_Management_Local_AE__c,
        Opp_Job_Number__c, Opp_Facility_City__c, Opp_Facility__c, Opp_Exhibit_Hall__c,
        Opp_Square_Footage__c, Opp_Exhibitor_Count__c, Opp_Producing_Branch__c, Opp_Show_Move_In__c,
        Opp_Show_Move_Out__c, Opp_Show_Opening_Date__c, Opp_Show_Close_Date__c,
        Do_we_have_overhead_rigging__c, Do_we_have_electrical_revenue__c,
        Do_we_have_cleaning_revenue__c ,Are_any_exhibitor_rates_contracted__c,
        Std_Exhibitor_City_Deco_Pricing__c, Management_Commissions__c, Facility_Commissions__c,
        Show_Cost_Revenue_Impact_year_over_year__c, Shared_Opportunities_from_show_to_show__c,
        Information_assistance_possibilities__c, Any_Significant_Show_Changes_YOY__c,
        Exhibitor_Sales_Marketing_Opportunities__c, Anything_else_that_we_should_know__c,
        Management_Freight_Details__c, Freight_Billing__c, Job_Numbers__c, Graphic_Sq_ft__c,
        Exhibitor_Freight_Weight__c, Carpet_Sq_Yards__c, Show_Name__c, Customs__c, Other__c,
        Overhead_Rigging__c, Cleaning__c, Utilities__c, Exhibit_Transportation__c, Freight__c,
        Decorating__c, Show_Management__c, Advance_Warehouse_Crated_ST__c, Advance_Warehouse_Crated_OT__c,
        Adv_WH_Special_Handling_ST__c, Adv_WH_Special_Handling_OT__c, Showsite_Crated_ST__c,
        Showsite_Crated_OT__c, Showsite_Special_Handling_ST__c, Showsite_Special_Handling_OT__c,
        I_D_Labor_ST__c, I_D_Labor_OT__c, I_D_Labor_DT__c, X9x10_Std_Booth_Carpet__c,
        Arm_Chair_Black_Diamond__c, X6_Skirted_Table__c, Net_Square_Footage__c, Exhibitor_Count__c,
        Opportunity__c, Budget_FY__c, wk1_Mon__c, wk1_Tue__c, wk1_Wed__c, wk1_Thu__c, wk1_Fri__c,
        wk1_Sat__c, wk1_Sun__c, wk2_Mon__c, wk2_Tue__c, wk2_Thu__c, wk2_Wed__c, wk2_Fri__c,
        wk2_Sat__c, wk2_Sun__c, wk3_Mon__c, wk3_Tue__c, wk3_Wed__c, wk3_Thu__c, wk3_Fri__c, wk3_Sat__c,
        wk3_Sun__c, wk4_Mon__c, wk4_Tue__c, wk4_Wed__c, wk1_Mon_Holiday__c, wk1_Tue_Holiday__c,
        wk1_Wed_Holiday__c, wk1_Thu_Holiday__c, wk1_Fri_Holiday__c, wk1_Sat_Holiday__c,
        wk1_Sun_Holiday__c, wk2_Mon_Holiday__c, wk2_Tue_Holiday__c, wk2_Wed_Holiday__c,
        wk2_Thu_Holiday__c, wk2_Fri_Holiday__c, wk2_Sat_Holiday__c, wk2_Sun_Holiday__c,
        wk3_Mon_Holiday__c, wk3_Tue_Holiday__c, wk3_Wed_Holiday__c, wk3_Thu_Holiday__c,
        wk3_Fri_Holiday__c, wk3_Sat_Holiday__c, wk3_Sun_Holiday__c, wk4_Mon_Holiday__c,
        wk4_Tue_Holiday__c, wk4_Wed_Holiday__c, Opportunity_Owner__c, Opportunity_Owner__r.Name,
        Acct_Mgmt_Producing__c, Acct_Mgmt_Producing__r.Name, Acct_Mgmt_Local_AE__c,
        Acct_Mgmt_Local_AE__r.Name, City__c, Venue_Facility__c, Halls__c,
        Prior_carry_forward_amortization_expense__c, Mgmt_Commission_Calculation__c,
        Facility_Commissions_Calculation__c, Material_Handling_Package__c, Total_Revenue__c,
        Year_of_Contract__c, Opportunity__r.Local_Account_Manager__c, Opportunity__r.Account_Manager__c,
        Opportunity__r.ownerId,Opportunity__r.Job_Cost_Actual__c, Opportunity__r.Reported_Revenue__c, Opportunity__r.Amount, Opportunity__r.Forecasted_Job_Cost__c
        From Budget_Years__r) From Opportunity o where Show_Campaign_ID__c = :campOpp.Show_Campaign_ID__c limit 5]);

       
Prabhat Kumar12Prabhat Kumar12
You need to check your where claouse field. Make sure it does not return null or create that field as external ID, it will index the field.
murdocmurdoc
I thought so, but I was wondering what would be the exact change. Here is the portion where the error is, at least according to eclipse:
        System.currentPageReference().getParameters().put('opportunityId', o4.Id);
        List<Opportunity> listOpps1 = new List<Opportunity>([Select o.AccountId, o.Show_Campaign_ID__c,

How would I add a wher clause in refernce to an ID field? I really appreciate your help.