• Hemant Rana 14
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
List<Campaign> campOBj=[Select id from campaign];
Set<Id> campId=new Set<Id>();
For(Campaign campValues : campOBj)
{
    campId.add(campValues.id);
}
For(Id campIdV : campId)
{
    List<campaignMember> countCM=[Select id from campaignMember where campaignid = : campIdV limit 30000];
}

This is a simple code but its giving error:
System.LimitException: Too many query rows: 50001

In my org their is total number of CAMPAIGN='66'
when is see in my DEBUG: it only work for 12 CAMPAIGN then gives this error:

Values in Debug Log-----
**campId701D0000000d0MQIAY
***count13516
**campId701D0000000cxAWIAY
***count10156
**campId701D0000000cylEIAQ
***count3833
**campId701D0000000cxXpIAI
***count14084
**campId701D0000000cxrfIAA
***count1
**campId701D0000000cwzFIAQ
***count3606

for rest of the 6 campaign its giving 0 count thats why i didnt mention here and after that for this campaign id its showing error and the debug stops-
**campId701D0000000cyZDIAY

what i was thinking when i added all the count its approx 46000 i think thats why the count is going more than 50,000 but its not possible can anyone give me a possible ans why this is giving error. as soql doesn't work like this.
 
List<Campaign> campOBj=[Select id from campaign];
Set<Id> campId=new Set<Id>();
For(Campaign campValues : campOBj)
{
    campId.add(campValues.id);
}
For(Id campIdV : campId)
{
    List<campaignMember> countCM=[Select id from campaignMember where campaignid = : campIdV limit 30000];
}

This is a simple code but its giving error:
System.LimitException: Too many query rows: 50001

In my org their is total number of CAMPAIGN='66'
when is see in my DEBUG: it only work for 12 CAMPAIGN then gives this error:

Values in Debug Log-----
**campId701D0000000d0MQIAY
***count13516
**campId701D0000000cxAWIAY
***count10156
**campId701D0000000cylEIAQ
***count3833
**campId701D0000000cxXpIAI
***count14084
**campId701D0000000cxrfIAA
***count1
**campId701D0000000cwzFIAQ
***count3606

for rest of the 6 campaign its giving 0 count thats why i didnt mention here and after that for this campaign id its showing error and the debug stops-
**campId701D0000000cyZDIAY

what i was thinking when i added all the count its approx 46000 i think thats why the count is going more than 50,000 but its not possible can anyone give me a possible ans why this is giving error. as soql doesn't work like this.