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
bbyrnebbyrne 

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error even when SOQL contains an explicit limit

Hi all,

 

I'm trying to run a batch process based on a CronKit trigger. The goal of the process is to find all opportunities in a given state and to then create new leads for those opportunities. Everything works fine in the sandbox environment but the governor limits are clamping down on my SOQL even though I limit the number of rows to 100. Any help would be greatly appreciated. 

 

 

public Integer bulkRecycleOpportunities(String opportunityStage) { List<Lead> leadList = new List<Lead>(); if (opportunityStage == OPP_STAGE_CANCEL) { List<Opportunity> opportunityList = new List<Opportunity>([select id, account.yelp_business_id__c, account.business__c, account.business_name__c from opportunity where stageName =:OPP_STAGE_CANCEL and account.last_payment_date__c < LAST_N_DAYS:180 limit 100]); for (Opportunity opportunity:opportunityList) { leadList.add(createLeadFromOpportunity(opportunity)); } } else if (opportunityStage == OPP_STAGE_RECYCLE) { List<Opportunity> opportunityList = new List<Opportunity>([select id, account.yelp_business_id__c, account.business__c, account.business_name__c from opportunity where stageName =:OPP_STAGE_RECYCLE and lastModifiedDate < LAST_N_DAYS:60 limit 100]); for (Opportunity opportunity:opportunityList) { leadList.add(createLeadFromOpportunity(opportunity)); } } insertLeadList(leadList); return leadList.size(); }

 

Here's the full error message in case it helps 

 

 

 

 

Run Failures:bulkRecycler.testCustomBatchTrigger System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, recycleOpportunitiesTrigger: execution of BeforeInsertcaused 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)

 


 

 

Anand@SAASAnand@SAAS

Looks like your query is going against a very large data set and causing this issue.

 

 

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)

 Typically this is solved by "indexing" the field that you are using in the SOQL. Contact your Salesforce support rep to follow through.

 

 

Ankit AroraAnkit Arora

Hi,

 

I don't think there is any problem with your code. Its just there is some problem at FLS(Field Level Security) of Activity. Please make sure all fields of Activity , Task and Event is visible for System Administrator on both orgs (Also opportunity fields which your are using). Hopefully this will resolve your problem.

 

If this still doesn't resolves your problem then make sure CRUD rights are given to objects which you are using in this code.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Raj_ThaparRaj_Thapar

Have you tried to put condition on query. You can use created date for example "created date is > 01/01/1999" or you can make conditional queries with AND.