You need to sign in to do that
Don't have an account?
System.LimitException: Too many code statements: 200001
I'm getting this system error when trying to update just a small list of properties. Can anyone assist? It works as expected on a single record - but more than one hits limit pretty quickly.
This code should write 4 fields on a property object if a checkbox called writecodes is TRUE.
This is code that is triggered by a 'before update' trigger.
Apex Class:
public class PropertyProductCodes{
Public List<Property_Account__c> lstNewProps = new List<Property_Account__c>();
Public List<Property_Account__c> lstOldProps = new List<Property_Account__c>();
public void ProductCodes(){
List<Case> propertycases = [select Id,Product_Code__c,IsClosed FROM case where Property__c IN: lstNewProps AND XLS01__c=:TRUE AND Status!=:'Cancelled'];
List<Property_Account__c> props = new List<Property_Account__c>();
String codes;
String SEO = 'SEO';
String SEOcodes;
Integer SEOlen=3;
Integer SEOindex;
Integer SEOcount = 0;
Integer SEOclosed = 0;
String LSCW = 'LSCW';
String LSCWcodes;
Integer LSCWlen=4;
Integer LSCWindex;
Integer LSCWcount = 0;
IF(lstNewProps.size()>0 && propertycases.size()>0){
For(Property_Account__c NewProps: lstNewProps){
IF(NewProps.WriteCodes__c == True){
For(Case wc : propertycases){
IF(codes==null && wc.IsClosed==False){
codes=wc.product_code__c+'F';
}
Else IF(codes==null && wc.IsClosed==True){
codes=wc.product_code__c+'T';
IF(wc.product_code__c.contains(SEO)==TRUE){
SEOclosed++;
}
}
Else IF(wc.IsClosed==False){
codes=codes+'-'+wc.product_code__c+'F';
}
Else{
codes=codes+'-'+wc.product_code__c+'T';
IF(wc.product_code__c.contains(SEO)==TRUE){
SEOclosed++;
}
}
}
SEOcodes=codes;
SEOindex=SEOcodes.indexOf(SEO);
while(SEOindex >=0){
SEOcount++;
SEOcodes=SEOcodes.substring(SEOindex+SEOlen);
SEOindex=SEOcodes.indexOf(SEO);
}
LSCWcodes=codes;
LSCWindex=LSCWcodes.indexOf(LSCW);
while(LSCWindex >=0){
LSCWcount++;
LSCWcodes=LSCWcodes.substring(LSCWindex+LSCWlen);
LSCWindex=LSCWcodes.indexOf(LSCW);
}
props.add(NewProps);
NewProps.SEO_Count__c=SEOcount;
NewProps.LSCW_Count__c=LSCWcount;
NewProps.SEO_Closed__c=SEOclosed;
NewProps.ImplementationCodes__c=codes;
NewProps.WriteCodes__c=False;
SEOcodes=Null;
SEOindex=0;
SEOcount=0;
SEOclosed=0;
LSCWcodes=Null;
LSCWindex=0;
LSCWcount=0;
codes=Null;
}
}
}
}
}
Here is trigger:
Here is the before update trigger:
trigger PropertyUpdates on Property_Account__c (before update) {
public PropertyProductCodes clsPropertyProductCodes=new PropertyProductCodes();
clsPropertyProductCodes.lstNewProps = Trigger.new;
clsPropertyProductCodes.lstOldProps = Trigger.old;
clsPropertyProductCodes.ProductCodes();
}
Note - this works as expected on a single record. But I need it bulkified for sure.