function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dan231Dan231 

caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows

Hello All,

I am getting this error, Can any help on this ?

  for(Contact cc : [select id,name,LastName,Email from Contact]){
            ContactLastNameEmailMap.put(cc.LastName+'-'+cc.Email,cc);
        }
      
        for (eo3__Composite_Project__c CompositeProj : newCompositeProject){
            SiteIdSet.add(CompositeProj.eo3__Site_External_Id__c);
        }
       
        List<eo3__eoSite__c> siteList=new List<eo3__eoSite__c >();
        siteList=Database.query('Select id,name,eo3__Account__c,eo3__External_ID__c  from eo3__eoSite__c Where eo3__External_ID__c in:SiteIdSet');
        for(eo3__eoSite__c ss : siteList){
            siteMap.put(ss.eo3__External_ID__c,ss);
        }
        // Checking for duplicat contact, if exist then we will assign it to Primary project contact else we will create it and then assign it.
        for (eo3__Composite_Project__c CompositeProj : newCompositeProject){  
               
                if(ContactLastNameEmailMap!=null && ContactLastNameEmailMap.Get(CompositeProj.eo3__Contact_Last_Name__c+'-'+CompositeProj.eo3__Contact_Email_Address__c)!=null){
                   //If Contact already exists with inserted/updated Last name and Email that assiging that contact as Primary Project Contact
                    CompositeProj.Primary_Project_Contact__c=ContactLastNameEmailMap.Get(CompositeProj.eo3__Contact_Last_Name__c+'-'+CompositeProj.eo3__Contact_Email_Address__c).ID;
                }


Thanks,
William LópezWilliam López
Hello Dan231,

I think the issue is that you have a lot of Records Maybe in the first SOQL  "select id,name,LastName,Email from Contact" or in the second one "from eo3__eoSite__c"

There is 2 way that I can think to fix this:

1) Use a WHERE condition, so you only get the contacts that you need, not all of them, this way you will have last than 100000 records. 

2) Move the logic to a batch class. Using a batch you can process big amount of data, the logic will run by parts. Here is an example about how to use Batch apex.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

I hope this helps.

 
Waqar Hussain SFWaqar Hussain SF
for(Contact cc : [select id,name,LastName,Email from Contact limit 9999]){
            ContactLastNameEmailMap.put(cc.LastName+'-'+cc.Email,cc);
        }
      
        for (eo3__Composite_Project__c CompositeProj : newCompositeProject){
            SiteIdSet.add(CompositeProj.eo3__Site_External_Id__c);
        }
       
        List<eo3__eoSite__c> siteList=new List<eo3__eoSite__c >();
        siteList=Database.query('Select id,name,eo3__Account__c,eo3__External_ID__c  from eo3__eoSite__c Where eo3__External_ID__c in:SiteIdSet' limit 9999);
        for(eo3__eoSite__c ss : siteList){
            siteMap.put(ss.eo3__External_ID__c,ss);
        }
        // Checking for duplicat contact, if exist then we will assign it to Primary project contact else we will create it and then assign it.
        for (eo3__Composite_Project__c CompositeProj : newCompositeProject){  
               
                if(ContactLastNameEmailMap!=null && ContactLastNameEmailMap.Get(CompositeProj.eo3__Contact_Last_Name__c+'-'+CompositeProj.eo3__Contact_Email_Address__c)!=null){
                   //If Contact already exists with inserted/updated Last name and Email that assiging that contact as Primary Project Contact
                    CompositeProj.Primary_Project_Contact__c=ContactLastNameEmailMap.Get(CompositeProj.eo3__Contact_Last_Name__c+'-'+CompositeProj.eo3__Contact_Email_Address__c).ID;
                }
		}
Dan231Dan231
I am still getting this error