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
cooldamselcooldamsel 

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);
                                }
                            }
                        }

Best Answer chosen by cooldamsel
Dhaval PanchalDhaval Panchal

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

Dhaval PanchalDhaval Panchal

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.

This was selected as the best answer
cooldamselcooldamsel

Thank You. Rather than that don't we have any other solution?

Dhaval PanchalDhaval Panchal
Try to use Map.
cooldamselcooldamsel
Ok i will try to use it.