0

I am Getting Error while Creating a record : Error: Invalid Data. Review all error messages below to correct your data. Apex trigger ManufacturerFieldUpdation caused an unexpected exception, contact your administrator: ManufacturerFieldUpdation: execution of BeforeUpdate 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.ManufacturerFieldUpdation: line 7, column 1

if(Trigger.isBefore){
List<SupplierContacts__c> vSc= new List<SupplierContacts__c>();
for(MCAR_Manufacturer__c mfr: trigger.new) {

    **vSc = [select id,Enterprise_ID__c,Supplier_Manager__c,Email__c from 
                  SupplierContacts__c where EnterId__c =:mfr.Enterprise_ID__c ];** 
    System.debug('Supplier Caontact Details are------>'+vSc); 
    System.debug('vsc size is---->'+vSc.Size());
    if(vSc.size()>0) {
       mfr.Supplier_Manager__c  = vSc[0].Supplier_Manager__c;
       mfr.Email__c=vSc[0].Email__c;
    }
} 

Please guide me in this case, I Marked the line where i am getting error

2
0

A good answer for GlynA from discussion boards is that

"Yes, that means it's taking too long. A couple ways to get more CPU time are to put the code in an @future method (you get 60 seconds of CPU instead of just 10 seconds), or implement it as a Batch Apex job. Since both of these methods are asynchronous, the trigger and associated DML will complete before the calls to the AccountServices methods are made - but they will be called eventually. "

is that a feasible?

HTH Prabhan

0

Problem is that you are try to query too many records in single SOQL. There is clear description in error message:

  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)

Consider what may happens if Enterprise_ID__c is null, and there are huge amount (more than 10000 records) of SupplierContacts__c with empty EnterId__c field, or just a lot of them with some concrete value - it would fail.

You can try to filter data set that you are trying to query by some clauses, or probably put a limit statement in your SOQL.

Also, every time for every record you are performing soql - that also bad practise - in case if you try to update more than 150 record of MCAR_Manufacturer__c object - it will fail. Useful links about limits and trigger bulkifying:

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm

http://www.sfdc99.com/2014/01/18/bulkifying-code/ https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.