You need to sign in to do that
Don't have an account?
HSDM Support
Trigger causes System.QueryException for 1 record
I have a Custom Object called Vehicle__c, which has a trigger called T_Vehicle_Seek_Ref_Values.
When I create a new vehicle record manually, I was hit with this error:
When I create a new vehicle record manually, I was hit with this error:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger T_Vehicle_Seek_Ref_Values caused an unexpected exception, contact your administrator: T_Vehicle_Seek_Ref_Values: execution of BeforeInsert 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): Trigger.T_Vehicle_Seek_Ref_Values: line 35, column 1
Apex trigger T_Vehicle_Seek_Ref_Values caused an unexpected exception, contact your administrator: T_Vehicle_Seek_Ref_Values: execution of BeforeInsert 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): Trigger.T_Vehicle_Seek_Ref_Values: line 35, column 1
Coding for my Trigger:
Why does this error occur now while I have had this trigger code running for years?
trigger T_Vehicle_Seek_Ref_Values on Vehicle__c (before insert, before update) { // list of EDMS Vehicle Model Id Set<String> vModelId = new Set<String>(); // list of EDMS Customer Id Set<String> vCustId = new Set<String>(); for (Vehicle__c v: Trigger.new) { vModelId.add(v.EDMS_Model_Id__c); vCustId.add(v.EDMS_Customer_Id__c); } // EDMS Model Id => SFDC Product Id Map<String, Id> mapModel = new Map<String, Id>(); for (Product2 model: [Select Id, EDMS_Model_Id__c From Product2 Where EDMS_Model_Id__c In :vModelId Limit 200]) { mapModel.put(model.EDMS_Model_Id__c, model.Id); } // EDMS Customer Id => SFDC Account/Contact Id Map<String, Account> mapCust = new Map<String, Account>(); for (Account acc: [Select Id, PersonContactId, IsPersonAccount, CustomerId__c, ContactCustomerId__pc From Account Where CustomerId__c In :vCustId Limit 200]) { mapCust.put(acc.CustomerId__c, acc); } // Update Vehicle object based on external Id for (Vehicle__c v: Trigger.new) { if (Trigger.isInsert) { if (mapModel.containsKey(v.EDMS_Model_Id__c)) v.Product__c = mapModel.get(v.EDMS_Model_Id__c); if (mapCust.containsKey(v.EDMS_Customer_Id__c)) { Account accTmp = mapCust.get(v.EDMS_Customer_Id__c); v.Account__c = accTmp.Id; if (accTmp.IsPersonAccount) v.Contact__c = accTmp.PersonContactId; } } else if (Trigger.isUpdate) { Vehicle__c o = Trigger.oldMap.get(v.Id); if (u.chg('EDMS_Model_Id__c', v, o)) { v.Product__c = mapModel.get(v.EDMS_Model_Id__c); } if (u.chg('EDMS_Customer_Id__c', v, o)) { if (mapCust.containsKey(v.EDMS_Customer_Id__c)) { Account accTmp = mapCust.get(v.EDMS_Customer_Id__c); v.Account__c = accTmp.Id; if (accTmp.IsPersonAccount) v.Contact__c = accTmp.PersonContactId; } } } } }Both EDMS_Model_Id__c and EDMS_Customer_Id__c fields were not populated when keyed in manually. They are used for data interface from another system.
Why does this error occur now while I have had this trigger code running for years?
I have removed the comment section on top of the Trigger.
Account.CustomerId__c is set as External ID, Unique Case Insensitive.
PS: How do I edit my own post?