I searched but didn't found anything about this error, but I'm facing it now. "Too many code statements: 200001"

The error specifies "code statements", I was familiar with script statements but didn't knew we have code statements error also in APEX.

How do we rectify this kind of error, does anyone know?

  • Is this happening in unmanaged code or a third-party package? – bigassforce Feb 21 '13 at 23:04
  • By any chance, is this happening in a test case when code is deployed to production? – Richard N Feb 21 '13 at 23:33
  • This has happened in user org, the code was working perfectly fine for last one year and then boom the error :) .. I suspected it could have been due to data increased in past year and my code was doing some looping and that could have triggered the limit. – VarunC Feb 22 '13 at 14:10

Apex statements are any coded instruction that performs an action. In Apex, statements must end with a semicolon and can be one of the following types:

  • Assignment, such as assigning a value to a variable
  • Conditional (if-else)
  • Loops
  • Do-while
  • While
  • For
  • Locking
  • Data Manipulation Language (DML)
  • Transaction Control
  • Method Invoking
  • Exception Handling

This was a pretty good blog on how to reduce your total statements. http://www.tgerm.com/2010/02/apex-script-statements-reduction-tips.html

Check out the Understanding Execution Governors and Limits doc to find out more information about the limits. http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

  • Thnx @jonnybro. The article points out some things, but I was peculiarly interested in knowing what would trigger "code statement" error. I know the limitation of continuously calling line of codes in loops and extra unneeded statement that would result in exceeding number of script statements error. – VarunC Feb 22 '13 at 8:20
  • @vc4u If you understand that, then is there anything you aren't understanding? Would love to help more with your class, but without any code im kind of limited. – jonnybro Feb 22 '13 at 8:38
  • i understand the issue. I suspected it to be a script statements issue. My code was doing a loop around in a for loop of records fetched, incidently even though I had filtering on the query, it fetched over 10000 records and thus in looping and processing it crossed over the script statements limit. I've corrected the code now. – VarunC Feb 22 '13 at 14:13

I was familiar with script statements but didn't knew we have code statements error also in APEX.

Just to clarify, as it sounds like you might be confused about the terminology: "Apex Statements", "Code Statements", and "Script Statements" are all talking about the same thing - so you'll need to first see if you can improve efficiency, then maybe consider whether you can run the offending code asynchronously in a @future method.

If your code is particularly complex, I find it helps to write out a pseudo-code version of what you're running, and try and simplify on paper, then implement; rather than hacking at it haphazardly :)

  • Yes @James thats what I thought of also, but then it doesn't make sense to me that there is need for different names for Apex Statement, Code Statement and Script Statement, if they all point out to same things :) ... – VarunC Feb 22 '13 at 8:24
  • That's understandable! There probably isn't really a need for different names, but they're definitely referring to the same thing – James Hill Feb 22 '13 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.