You need to sign in to do that
Don't have an account?
Production issue
HI all,
I am moving one trigger from sandbox account to production. in production account i have 34,200 contacts are there. i ma not getting any error while uploading . but I am getting failure message in production while validating the chage set. The Fialure message like ""System.LimitException: Too many query rows: 50001", Failure Stack Trace: "(System Code) Trigger.campMemberTrig: line 6, column 1" as 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 limti 50000])---------- 6th line I tried 49000 limit a but //no Use same error iam getting once
mpcon.put(c.id,c);
id contactid;
for(CampaignMember cm:trigger.New) {
if(cm.status=='Opted Out'&&trigger.isinsert)
contactid=cm.contactid;
else if(trigger.isupdate)
if(trigger.oldmap.get(cm.id).status!='Opted Out'&&cm.status=='Opted Out')
contactid=cm.contactid;
}
If(contactid!=null){
string cemail=mpcon.get(contactid).email;
for(id cid:mpcon.keyset())
{
If(mpcon.get(cid).email==cemail){
mpcon.get(cid).HasOptedOutOfEmail=true;
conlist.add(mpcon.get(cid));
}
}
}
if(conlist.size()>0)
update conlist;
}
Plz help me out this situation
Nageswara
Hi,
You know that Total number of records retrieved by SOQL queries is 50,000.
Here I would like to specify one point
The total number of SOQL queries means not by a single Query.
It will consider the total number of rows Retrieved by that Particular instance.
In your case the code which caused to fire this Trigger already queried some records
So even though if you are trying to query only 34,200 this count will be added to that already queried records count.
So that total count is reaching more than 50,000
In your case
Records Queried by code causing this trigger fire+ query in trigger >50,000.
Because of this reason you are getting this error.
To solve this problem you need to Filter that queries by using where condition (better use Index Fields)
So that the number of queries returned will be decreased and you will get rid of this problem.
Same i have posted here also.
http://boards.developerforce.com/t5/Apex-Code-Development/Urgent-Trigger-error/td-p/475329
All Answers
Hi,
Instead of hardcoding the limit, why dont you use the limit methods?
Please go through below link for dicumentation.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_limits.htm
Hi,
You know that Total number of records retrieved by SOQL queries is 50,000.
Here I would like to specify one point
The total number of SOQL queries means not by a single Query.
It will consider the total number of rows Retrieved by that Particular instance.
In your case the code which caused to fire this Trigger already queried some records
So even though if you are trying to query only 34,200 this count will be added to that already queried records count.
So that total count is reaching more than 50,000
In your case
Records Queried by code causing this trigger fire+ query in trigger >50,000.
Because of this reason you are getting this error.
To solve this problem you need to Filter that queries by using where condition (better use Index Fields)
So that the number of queries returned will be decreased and you will get rid of this problem.
Same i have posted here also.
http://boards.developerforce.com/t5/Apex-Code-Development/Urgent-Trigger-error/td-p/475329
Suggestions given above will definitely help you, still a small add on. If it is only concerned with deploying the change set and passing the test class failures then make sure you have used
@isTest(SeeAllData=false)
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Nageswara,
To resolve these type of issue, you can add conditions of select statements by adding below line.
if(Test.IsRunningTest()==true) {
///Use select query by adding limit of 10 records
}
else {
//use your regular query here.
}
However, it looks like the logic is not correct above because you have not added any criteria in your select statement and it may result into error when you reached to 50000 contacts into production.
Please describe that what you are trying to do here. so you will get better solution to write this trigger with different logic with taken care of SF governor limits.
Regards,
Kamlesh Chauhan, (Founder & Chief Solutions Architect)
LogicRain Technologies, (Salesforce and Force.com Development Division)
Cellular: +91-(997) 476-6800 Office: (732) 676-6400 Skype: kamlesh.logicrain
kamlesh@logicrain.com || http://www.logicrain.com || LinkedIn