function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anu-SFDCAnu-SFDC 

Too Many Script Statements:200001

Hi, I have a managed package in my instance.. I have created a trigger in my sandbox instance.. But When I run the test classes it is showing too many scriot statements error.. Here is my code: trigger dateConvert on CnP__CnP_Transaction__c (before insert) { for(CnP__CnP_Transaction__c c:Trigger.new){ c.CnP__bSource__c = Integer.valueOf(c.CnP__bSource__c); if(c.CnP__bSource__c == 2 ){ String delimslash = '/'; String[] DDate; Datetime myDate; String tdate = c.Dummy_Field__c; if(tdate!=null){ String[] splitdate = tdate.split(' '); DDate = splitdate.get(0).split('/'); String TTime = splitdate.get(1); String month = DDate.get(0); String day = DDate.get(1); String year = DDate.get(2); String hour = TTime.split(':').get(0); String minute = TTime.split(':').get(1); String second = '00'; myDate = datetime.newInstance(integer.ValueOf(year),integer.ValueOf(month), integer.ValueOf(day), integer.ValueOf(hour), integer.ValueOf(minute), integer.ValueOf(second)); c.CnP__TransactionDate__c = myDate; c.CnP__TransactionTimeZone__c = myDate; } } } } Help me Regarding this. Anu
Anu-SFDCAnu-SFDC

Sorry

 

It was the allignment problem

 

 

trigger dateConvert on CnP__CnP_Transaction__c (before insert) {
    for(CnP__CnP_Transaction__c c:Trigger.new){ 

  c.CnP__bSource__c = Integer.valueOf(c.CnP__bSource__c);

    if(c.CnP__bSource__c == 2){ 

         c.CnP__TotalCharged__c  = c.CnP__Amount__c; 

         c.CnP__TotalDue__c = c.CnP__Amount__c; 

        c.CnP__Organization_Name__c = c.CnP__Last_Name__c;

             String delimslash = '/'; 

   String[] DDate;  

   Datetime myDate;

     String tdate = c.Dummy_Field__c; 

 if(tdate!=null){ 

      String[] splitdate = tdate.split(' ');   

    DDate = splitdate.get(0).split('/');   

    String TTime = splitdate.get(1);     

  String   month = DDate.get(0);   

    String   day = DDate.get(1);     

  String   year = DDate.get(2);       

String   hour = TTime.split(':').get(0); 

   String   minute = TTime.split(':').get(1);   

    String   second = '00';


    myDate = datetime.newInstance(integer.ValueOf(year),integer.ValueOf(month), integer.ValueOf(day),integer.ValueOf(hour), integer.ValueOf(minute), integer.ValueOf(second));   

      c.CnP__TransactionDate__c = myDate; 

        c.CnP__TransactionTimeZone__c = myDate;     

  }     

}   

}
}

mngmng

Minor comments about this trigger...

trigger dateConvert on CnP__CnP_Transaction__c (before insert)
{
	for(CnP__CnP_Transaction__c c:Trigger.new)
	{	
		// why is this line needed? if the original field wasn't an integer
		// in the first place, could you even set it back? or is it a decimal
		// with multiple decimal points? if you need it to be an int, why
		// not just remove the decimal places?
		c.CnP__bSource__c = Integer.valueOf(c.CnP__bSource__c);
		if(c.CnP__bSource__c == 2)
		{ 
			c.CnP__TotalCharged__c  = c.CnP__Amount__c; 
			c.CnP__TotalDue__c = c.CnP__Amount__c; 
			c.CnP__Organization_Name__c = c.CnP__Last_Name__c;
			// move these instantiations out, since they cost lines
			String delimslash = '/'; 
			String[] DDate;  
			Datetime myDate;
			String tdate = c.Dummy_Field__c; 
			if(tdate!=null)
			{ 
				// this costs so many lines
				// if you can ensure that the incoming values are standardized,
				// consider using the DateTime.parse method
				// http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_datetime.htm?SearchType=Stem
				String[] splitdate = tdate.split(' ');   
				DDate = splitdate.get(0).split('/');   
				String TTime = splitdate.get(1);     
				String month = DDate.get(0);   
				String day = DDate.get(1);     
				String year = DDate.get(2);       
				String hour = TTime.split(':').get(0); 
				String minute = TTime.split(':').get(1);   
				String second = '00';
				myDate = datetime.newInstance(integer.ValueOf(year),integer.ValueOf(month), integer.ValueOf(day),integer.ValueOf(hour), integer.ValueOf(minute), integer.ValueOf(second));   
				c.CnP__TransactionDate__c = myDate; 
				c.CnP__TransactionTimeZone__c = myDate;     
			}     
		}   
	}
}

 

Ultimately, it's a basic need for optimizations across ALL code that runs when those objects are being modified. Just because the execution fails in this trigger doesn't necessarily mean that this trigger is the offender. Yes, this trigger can gain something from optimizations, but even with 200 records ( the maximum batch size ) this trigger can only contribute up to 8000 lines out of 200000.

 

There's a lot more investigation to be done, such as what other related records get updated from the original object, and see what kinds of triggers fire from those, etc etc.