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
NareshKrishnaNareshKrishna 

Need help to avoid exception "Too many script statements: 200001"

Hi All,

 

Could anyone please suggest me the steps to reduce script statements in the application to avoid the exception "Too many script statements: 200001".

Thanks.

Navatar_DbSupNavatar_DbSup

Hi,

 

It means that your code has executed 20001 lines of apex.Too many script statements could indicate you are running a lot of loops, or one loop a really long time (like maybe infinite?). If you can't find an infinite loop, you might try throwing in some system.debug statements that check how many script statements there have been so far.
This Error has occurred due to use of too many scripts in your code , for this try to make less use of Looping statement

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Sam27Sam27

Totally agree with Navatar........you are most probably running some big logic in a loop and since the loop is running a lot of time your script running is getting out of limit i.e. more than 200000................try to customize your code.....

 

in the beginning or in the end of loop put a debug statement to check the script ran per iteration. system.debug(" scripts ran "+Limits.getScriptStatements() )

 

you can also do something likein the beginning or end of the loop

 

if(Limits.getScriptStatements() >180000){

break;

}

 

This will break the loop as soon as it crosses the 180000 mark in the iteration......adjust this number accordingly.......

 

However a genuine advice would be that instead of running that big a loop in one runtime....break that loop in some parts and run them in different runtime...

 

Hope that helps.