• HSDM Support
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
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:
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

 
Coding for my Trigger:
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?
Here is my full error message:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: T_TSC_Seek_Vehicle_Obj: 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_TSC_Seek_Vehicle_Obj: line 41, column 1
 
trigger T_TSC_Seek_Vehicle_Obj on Technical_Service_Campaign__c (before insert, before update) {

	//	list of Model, Chassis Number, Service Records
	//Set<String> tscModel		= new Set<String>();
	Set<String> tscChassis		= new Set<String>();
	Set<String> tscBrRepOrd		= new Set<String>();
	
	for (Technical_Service_Campaign__c tsc: Trigger.new) {
		//tscModel.add(tsc.Recall_Model_Code__c);
		tscChassis.add(tsc.Recall_Chassis__c);
		tscBrRepOrd.add(tsc.Recall_Branch_Code__c + tsc.Recall_Repair_Order__c);
	}

	//  TSC Recall Chassis => SFDC Vehicle Id, SFDC Product Id
	Map<String, Id> mapVehicle = new Map<String, Id>();
	Map<String, Id> mapProduct = new Map<String, Id>();
	Vehicle__c[] vs = [Select Id, EDMS_Chassis_Number__c, Product__r.Id
					   From Vehicle__c
					   Where EDMS_Chassis_Number__c In :tscChassis
					   Limit 200];
	for (Vehicle__c v: vs) {
		//	gather Vehicle Id, Model Id
		mapVehicle.put(v.EDMS_Chassis_Number__c, v.Id);
		mapProduct.put(v.EDMS_Chassis_Number__c, v.Product__r.Id);
	}

	//	TSC Recall Repair Order, Branch Code => SFDC Service Records
	Map<String, Id> mapSvcRec = new Map<String, Id>();
	Service_Record__c[] srs = [Select Id, Branch_Repair_Order__c
							   From Service_Record__c
							   Where Branch_Repair_Order__c In :tscBrRepOrd
							   Limit 200];

	for (Service_Record__c sr: srs) {
		system.debug('T_TSC_Seek_Vehicle_Obj: SR matched: ' + sr);
		mapSvcRec.put(sr.Branch_Repair_Order__c, sr.Id);
	}

	//	Update Technical Service Campaign object based on external Id	
	for (Technical_Service_Campaign__c tsc: Trigger.new) {
		if (mapVehicle.containsKey(tsc.Recall_Chassis__c)) {
			tsc.Vehicle__c = mapVehicle.get(tsc.Recall_Chassis__c);
			tsc.Model__c = mapProduct.get(tsc.Recall_Chassis__c);
		}

		if (mapSvcRec.containsKey(tsc.Recall_Branch_Code__c + 
								  tsc.Recall_Repair_Order__c)) {
			tsc.Service_Record__c = mapSvcRec.get(tsc.Recall_Branch_Code__c + 
								  				  tsc.Recall_Repair_Order__c);
		}
	}
}
This trigger runs fine in Sandbox. Problem occurs when new records are being Upsert in Production. Did a lot of searches, but most problems were related to Opportunity object. Mine is a Custom Object.

I have similar Trigger for other Custom Objects, which worked fine previously, until the recent update by SFDC (Fall 2015? I don't live in 4 seasons country.). Things start crumbling 1 by 1. I had to remark this whole piece of code in order for data to be loaded into Production. With that being said, the new records would have empty Lookup field, which should reference to respective Vehicles.

Records are upserted via batch job of 50 records.

Thank for your time.
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:
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

 
Coding for my Trigger:
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?
Here is my full error message:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: T_TSC_Seek_Vehicle_Obj: 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_TSC_Seek_Vehicle_Obj: line 41, column 1
 
trigger T_TSC_Seek_Vehicle_Obj on Technical_Service_Campaign__c (before insert, before update) {

	//	list of Model, Chassis Number, Service Records
	//Set<String> tscModel		= new Set<String>();
	Set<String> tscChassis		= new Set<String>();
	Set<String> tscBrRepOrd		= new Set<String>();
	
	for (Technical_Service_Campaign__c tsc: Trigger.new) {
		//tscModel.add(tsc.Recall_Model_Code__c);
		tscChassis.add(tsc.Recall_Chassis__c);
		tscBrRepOrd.add(tsc.Recall_Branch_Code__c + tsc.Recall_Repair_Order__c);
	}

	//  TSC Recall Chassis => SFDC Vehicle Id, SFDC Product Id
	Map<String, Id> mapVehicle = new Map<String, Id>();
	Map<String, Id> mapProduct = new Map<String, Id>();
	Vehicle__c[] vs = [Select Id, EDMS_Chassis_Number__c, Product__r.Id
					   From Vehicle__c
					   Where EDMS_Chassis_Number__c In :tscChassis
					   Limit 200];
	for (Vehicle__c v: vs) {
		//	gather Vehicle Id, Model Id
		mapVehicle.put(v.EDMS_Chassis_Number__c, v.Id);
		mapProduct.put(v.EDMS_Chassis_Number__c, v.Product__r.Id);
	}

	//	TSC Recall Repair Order, Branch Code => SFDC Service Records
	Map<String, Id> mapSvcRec = new Map<String, Id>();
	Service_Record__c[] srs = [Select Id, Branch_Repair_Order__c
							   From Service_Record__c
							   Where Branch_Repair_Order__c In :tscBrRepOrd
							   Limit 200];

	for (Service_Record__c sr: srs) {
		system.debug('T_TSC_Seek_Vehicle_Obj: SR matched: ' + sr);
		mapSvcRec.put(sr.Branch_Repair_Order__c, sr.Id);
	}

	//	Update Technical Service Campaign object based on external Id	
	for (Technical_Service_Campaign__c tsc: Trigger.new) {
		if (mapVehicle.containsKey(tsc.Recall_Chassis__c)) {
			tsc.Vehicle__c = mapVehicle.get(tsc.Recall_Chassis__c);
			tsc.Model__c = mapProduct.get(tsc.Recall_Chassis__c);
		}

		if (mapSvcRec.containsKey(tsc.Recall_Branch_Code__c + 
								  tsc.Recall_Repair_Order__c)) {
			tsc.Service_Record__c = mapSvcRec.get(tsc.Recall_Branch_Code__c + 
								  				  tsc.Recall_Repair_Order__c);
		}
	}
}
This trigger runs fine in Sandbox. Problem occurs when new records are being Upsert in Production. Did a lot of searches, but most problems were related to Opportunity object. Mine is a Custom Object.

I have similar Trigger for other Custom Objects, which worked fine previously, until the recent update by SFDC (Fall 2015? I don't live in 4 seasons country.). Things start crumbling 1 by 1. I had to remark this whole piece of code in order for data to be loaded into Production. With that being said, the new records would have empty Lookup field, which should reference to respective Vehicles.

Records are upserted via batch job of 50 records.

Thank for your time.