+ Start a Discussion
Nageswara  reddyNageswara reddy 

urgernt :Failure Message: "System.LimitException: Too many query rows: 50001", in Production

Hi All,


   I am  moving  tiggers from sanboz to production  account .  I  production account i have 34,240  records ,   wihile  validate the trigger in production  i am  gettting Error  like Failure Message: "System.LimitException: Too many query rows: 50001", Failure Stack Trace: "(System Code) Trigger.campMemberTrig: line 6, column 1"



 my trigger is




trigger campMemberTrig on CampaignMember (before insert, before update) {
    Map<Id, Contact> mpCon = new Map<Id, Contact>();
       list<contact> conlist=new list<contact>();
       for(Contact c: [Select id, name,email,HasOptedOutOfEmail from Contact limit 50000])----------6th line
    id contactid;
     for(CampaignMember  cm:trigger.New)  {
    if(cm.status=='Opted Out'&&trigger.isinsert)
    else if(trigger.isupdate)
    if(trigger.oldmap.get(cm.id).status!='Opted Out'&&cm.status=='Opted Out')
    is  there any  help to  solve  this error
V.S.K. ChowdaryV.S.K. Chowdary

You have to write the query


integer recordCount = [Select count() from Account where SomeCustomField__c = 'Client' limit 1001];


There is a link here that explains working with very large queries: http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm


In the examples they're not using LIMIT, so I doubt that'd be a problem.

They recommend using batch apex, although I'm not that familiar with it.


Sorry I can't be of any more help :(