You need to sign in to do that
Don't have an account?
System.LimitException: Too many script statements: 1000001 in Class
:smileysad::smileysad:
Hi All,
I have a urgent issue to be resolved. I have migrated my code into the production environment.
The code moved successfully in to the production area. But an issue arised on executing the piece of code in production.
I have written a batchable class to avoid governer limits, using the queryLoacator. Even then the issue isn't resolved.
Please enlighten me why such issues arise and provide some information on governor limits and how one could bypass them when bulk data query is required.
Please find my piece of code below.
global class Get_Account_Id_EPC implements Database.Batchable<sObject> { Public String Query; Global database.querylocator start(Database.BatchableContext BC){ Return database.getquerylocator(query); } Global void execute(Database.BatchableContext BC, List<SObject> scope) { List<Express_Payment__c> updatelist = new List<Express_Payment__c>(); List<Express_Payment__c> epsobj = [Select id,Agent__c,BP_ID__c,BP_Loc_Id__c from Express_Payment__c limit 1000]; for(Express_Payment__c records : epsobj){ for(sObject s : scope){ Account a = (Account)s; if(records.BP_ID__c!=null && records.BP_loc_ID__c!=null&&records.BP_ID__c == a.BPID__c && records.BP_Loc_Id__c == a.BP_Loc_Id__c){ records.Agent__c = a.id; updatelist.add(records); break; } } } update(updatelist); List<Utility_Bill_Payment__c> updatelist1 = new List<Utility_Bill_Payment__c>(); List<Utility_Bill_Payment__c> ubpobj = [Select id,Agent__c,BP_ID__c,BP_Loc_Id__c from Utility_Bill_Payment__c limit 1000]; for(Utility_Bill_Payment__c records : ubpobj){ for(sObject s : scope){ Account b = (Account)s; if(records.BP_ID__c!=null && records.BP_loc_ID__c!=null&&records.BP_ID__c == b.BPID__c && records.BP_Loc_Id__c == b.BP_Loc_Id__c){ records.Agent__c = b.id; updatelist1.add(records); break; } } } update(updatelist1); List<PrePaid_Card__c> updatelist2 = new List<PrePaid_Card__c>(); List<PrePaid_Card__c> ppcobj = [Select id,Agent__c,BP_ID__c,BP_Loc_Id__c from PrePaid_Card__c limit 1000]; for(PrePaid_Card__c records : ppcobj){ for(sObject s : scope){ Account c = (Account)s; if(records.BP_ID__c!=null && records.BP_loc_ID__c!=null&&records.BP_ID__c == c.BPID__c && records.BP_Loc_Id__c == c.BP_Loc_Id__c){ records.Agent__c = c.id; updatelist2.add(records); break; } } } update(updatelist2); List<MT_Volume_Reports__c> updatelist3 = new List<MT_Volume_Reports__c>(); List<MT_Volume_Reports__c> mtannualobj = [Select id,Agent__c,BPID__c,BP_Loc_Id__c from MT_Volume_Reports__c limit 1000]; for(MT_Volume_Reports__c records : mtannualobj){ for(sObject s : scope){ Account d = (Account)s; if(records.BPID__c!=null && records.BP_loc_ID__c!=null&&records.BPID__c == d.BPID__c && records.BP_Loc_Id__c == d.BP_Loc_Id__c){ records.Agent__c = d.id; updatelist3.add(records); break; } } } update(updatelist3); List<MT_Volume__c> updatelist4 = new List<MT_Volume__c>(); List<MT_Volume__c> mtobj = [Select id,Agent__c,BPID__c,BP_Loc_Id__c from MT_Volume__c limit 1000]; for(MT_Volume__c records : mtobj){ for(sObject s : scope){ Account e = (Account)s; if(records.BPID__c!=null && records.BP_loc_ID__c!=null&&records.BPID__c == e.BPID__c && records.BP_Loc_Id__c == e.BP_Loc_Id__c){ records.Agent__c = e.id; updatelist4.add(records); break; } } } update(updatelist4); List<MO_Volume__c> updatelist5 = new List<MO_Volume__c>(); List<MO_Volume__c> moobj = [Select id,Agent__c,BP_ID__c,BP_Loc_Id__c from MO_Volume__c limit 1000]; for(MO_Volume__c records : moobj){ for(sObject s : scope){ Account f = (Account)s; if(records.BP_ID__c!=null && records.BP_loc_ID__c!=null&&records.BP_ID__c == f.BPID__c && records.BP_Loc_Id__c == f.BP_Loc_Id__c){ records.Agent__c = f.id; updatelist5.add(records); break; } } } update(updatelist5); } Global void finish(Database.BatchableContext info){ } /* Test Coverage Class*/ Public static testMethod void SEUpdateTest() { User currentUser = [Select u.Id From User u Where u.Id =: UserInfo.getUserID()]; List<Account> testAccs = new List<Account>(); for(integer i=0;i<10;i++) { Account testAccount = new Account(Name = 'TestAccount'+i, OwnerId = currentUser.Id); testAccs.add(testAccount); } insert testAccs; Test.starttest(); Get_Account_Id_EPC sObj = new Get_Account_Id_EPC(); sObj.Query = 'Select id,BPID__c,BP_Loc_Id__c from Account'; ID BatchId = Database.executeBatch(sObj,500); test.stoptest(); AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id = :BatchId]; System.debug('\n\nFinal results are: '+a); //System.AssertEquals('Completed', a.status); //System.AssertEquals(0, a.NumberOfErrors); } }
Above is my batchable class.
Using below code i invoke the batchable class :
public void exec6(){ Get_Account_Id_EPC epcQuery = new Get_Account_Id_EPC(); epcQuery.Query = 'Select id,BPID__c,BP_Loc_Id__c from Account'; ID batchprocessid = Database.executeBatch(epcQuery); }
The issue arises when i tr to execute the code in production giving out an error System.LimitException: Too many script statements: 1000001, Pointing to the following line:
if(records.BP_ID__c!=null && records.BP_loc_ID__c!=null&&records.BP_ID__c == f.BPID__c && records.BP_Loc_Id__c == f.BP_Loc_Id__c)
I am failing to understand why this error is occuring. Please help me with the same.
I am running out of time :(
Any pointers are appreciated.
- TIA
Sushupsi
All Answers
In order to prevent infinite loops or very inefficient iterative database calls, the script execution framework throws a runtime exception if too many script statements are executed without any database statements. For more information, see Execution Model and Governors.
so within your for loop if there are too many rows (more than the limit) that doesn't satisfy your if condition ,it will fail..
I think if you move your if condition to soql where clause it might work.
if(records.BP_ID__c!=null && records.BP_loc_ID__c!=null&&records.BP_ID__c == b.BPID__c && records.BP_Loc_Id__c == b.BP_Loc_Id__c){
This could be included in the soql as ->
List<Utility_Bill_Payment__c> ubpobj = [Select id,Agent__c,BP_ID__c,BP_Loc_Id__c from Utility_Bill_Payment__c where bp_ID_C !=null and bp_loc_id__C !=null .....];
Then you don't need the if condition and fewer scripts will be run ..
hope this helps!
Sree
did that help?
Please help me I am getting the error
System.LimitException: Too many script statements: 200001
Class.ProductPriceBook1.: line 39, column 18 External entry point
Here is my code.
Please help