My question is in addition to the issue described here: System.LimitException: Too many query rows: 50001
What I don't understand is that my query only returns 1 row so how is it possible that I'm hitting a limit?
SELECT Id, CampaignId, ContactId, LeadId, F2F_Activity_ID__c, F2F_Activity_Subject__c, F2F_Activity_Date__c FROM CampaignMember WHERE ContactId = '003d000001wfzTe'
There are 350,000+ CampaignMember items but my WHERE
statement returns only 1 and is on ContactId (lookup field) which I believe is indexed. I have tried putting SOQL in a loop as suggested here as well and I still get System.LimitException: Too many query rows: 50001
All post on this topic mention setting a limit below 50k which I have tried and it works considering I will likely never have a single contact Id that has more than 10k campaign members. But the question is WHY does LIMIT fix this problem? The SOQL is still going to search all 350k+ CampaignMembers.
Note: Developer Console returns 1 row, but execute anonymous returns 50k+ (same SOQL)
003d000001wfzTe
). If I remove theWHERE
then yes 350k+ get returned. It would seem more likely that theContactId
field is not indexed but the documentation makes it appear it is so unless anyone else has insight about this I don't think that's the casequery explain
in Developer Console?query explain
in DC.