You need to sign in to do that
Don't have an account?
System.LimitException: Too many code statements: 200001
Hi,
I have written a class that displays data for a month. I developed and written test class. When i moved the code to production environment and validated i got the following error "System.LimitException: Too many code statements: 200001 "
I got my error in this following loop. I don't know what is the mistake i have done. Please help me.
for(RequirementAssignment__c ReqmAssignUser : FilterReqmtAssign)
{
System.Debug('Filtered Reqmt :' + ReqmAssignUser );
//Looping through the assign candidate list
for(Candidate_Mapping__c AssignCandt : lstAssignCandt)
{
//Filtering the list of requirements assigned for each assign candidate list.
if((AssignCandt.Requirement__c == ReqmAssignUser.Requirement__c) && (AssignCandt.CreatedBy.id == Users.id))
{
lstFilterAssignCandt.Add(AssignCandt);
}
}
}
There is no mistake in your code but it is because of large number of data.
for example,
suppose terReqmtAssign has more than 100000 records and also lstAssignCandt has more than 100000 records.
now you have used loop in loop. so (100000 X 100000) time you loop will be executed. and each steps are counted.
i.e. for(integer i=0; i<10;i++)
system.debug(i);
when this executed, it will count as 10 code statements.
so you need to optimize your logic. using break statement or other.
All Answers
There is no mistake in your code but it is because of large number of data.
for example,
suppose terReqmtAssign has more than 100000 records and also lstAssignCandt has more than 100000 records.
now you have used loop in loop. so (100000 X 100000) time you loop will be executed. and each steps are counted.
i.e. for(integer i=0; i<10;i++)
system.debug(i);
when this executed, it will count as 10 code statements.
so you need to optimize your logic. using break statement or other.
Thank You. Rather than that don't we have any other solution?