Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

My question is in addition to the issue described here: System.LimitException: Too many query rows: 50001System.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)

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)

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)

Source Link
Xtremefaith
  • 4.6k
  • 5
  • 44
  • 96

SOQL: Too many query rows even when only 1 is returned

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)