You need to sign in to do that
Don't have an account?
AnnaT
System.LimitException: Too many code statements: 200001
Please help me...
When I update over 1000 items at the same time, "System.LimitException: Too many code statements: 200001" error occurs.
I know the meaning of this error but I don't know how to modify my code...
Hereis a part of my Trigger;
if (Trigger.isInsert || Trigger.isUpdate) { List<ParentObject__c> pList = new List<ParentObject__c>(); for (ChildObject__c chld : Trigger.new) { ParentObject__c pObj = new ParentObject__c(); pObj.Id=chld.ParentLookupField__c; Boolean flag = false; if(pList.size()==0){ pList.add(pObj); } for(integer i=0;i<pList.size();i++){ if(pList[i].id==pObj.Id){ flag=true; }else if(flag==false){ pList.add(pObj); } } } update pdList; }
Thanks in advance for your support...
Anna
You are iterating over each record in the pList for every record in the Trigger.New list. You could rework your code to avoid this. Something like below should help reduce the total number of lines being called: