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

Deployment Failed - Can't reproduce with individual tests, not enough info given in message

Hey there Apexers,


I'm trying to deploy some code from my Sandbox to my production Enterprise org.  While deploying, the code generates a number of failures and as such cannot deploy.  My issue is that I cannot figure out why it fails.  


Running "All Tests" on both my production and sandbox org produces no errors

  • note: actually 14 failures, but they're all in managed packages from 3rd party vendors; marketo, geopoint, etc.
  • note 2: this is a functionality update to code previously deployed from sandbox to production

The "Deployment Results" page lists a table of failures, the rightmost column saying: 



Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, NewCampaignMemberTrigger: execution of AfterInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or c...


As the text is truncated, I'm not really getting any information about why it failed.  This is compounded by the fact that running the named test on both production and sandbox produces a pass; both as an individual test run and as a result of clicking "Run All Tests" from the Apex Class home page.


I've searched google with chunks of the message and found points about non-selective queries, etc, but as I have a lot of triggers I can't track down exactly what query is giving the problem.




At the risk of asking the obvious:


1. Do you have an object in production with more than 100K rows, and is your trigger querying it directly or through a called method?


If so, then you need to change your where clause or set one of the fields to external ID, as per the explanations you found through your searches.


2. Is your sandbox trigger different from your production trigger, especially if you are querying the object with > 100K rows?


If so, that would be the most likely reason why the production unit test passes.


What kind of DML does NewCampaignMemberTrigger do? If the trigger is after insert/update, it can't modify the collection that you're working with.


Thanks for the hints guys, turns out it is usually the most obvious explanation; just recently crossed the 100k mark


...not quite the full story.  I restructured a number of queries over CampaignMember, the object that recently crossed the 100k threshold.  In this process I dropped a where clause somehow, 'contactid in: contactIdList'.  Thus, when this update tried to push into production it was seeing 100k+ rows in an aggregate query when it should have been significantly limited.


Not sure if you know how limits are done for aggregate queries, so I'll copy/paste my post from another thread:


"FYI, aggregate queries count the number of records queried, not returned, for the limits.


So you have a COUNT() aggregate query, where 40,000 records have value X, and 30,000 records have value Y, that's not 2 rows, that's 70,000. Something to keep in mind."