I am using the execute anonymous window in developer console to execute a particular script in customer environment. The script is correct and is working in our local packaged environment but every time running the script in customer environment is giving execution failed error.

Previously also I faced the similar issue, the workaround I used is to divide the script into two smaller scripts and that worked. However, that can't be done here.

Is there a limit on number of statements or lines of code in execute anonymous window. I needs to run the script in customer environment to fix the code issues.

Any help would be highly appreciated.


  • Are you able to give exact details of the error and an example of the script you are trying to run? Oct 31, 2014 at 8:10
  • Please provide code that you are trying to execute in Developer console. Oct 31, 2014 at 8:45
  • All the normal governor limits apply when your run code this way so if the customer org has a lot more data than your testing org... One solution is to use SOQL LIMIT term so you can break the work up into many smaller pieces. Another is to crate and then run a Batchable class.
    – Keith C
    Oct 31, 2014 at 9:46

2 Answers 2


I've run into the same problem myself. I was attempting to run a script that is 525 lines long (feels messy but I'm trying to recreate the actions of a trigger to identify how different values are being calculated in a business process) in the execute anonymous window, and it was giving me the following error message:

Execution failed error message in developer console

Just for kicks, I then tried testing scripts of different length using just "System.debug('Hello world.');" in every line. After a few minutes I found a cutoff point - the script will run with 352 lines of the debug message, but fails at and after 353 lines.

System.debug script in developer console

Seems like a bit of a random cut-off point to me, so I suspect that value would change if you had more complex code like loops, SOQL queries, etc. I haven't been able to find any definitive info about the limits of an anonymous window in the Salesforce documentation.

Edit: I also tested this by adding in a few commented lines, and the number of comments affect the cut-off point as well (i.e., 352 debug lines work, 352 debug + 10 comment lines doesn't work).

  • 1
    I suspect that it's based on number of characters, not number of lines, as I had the same issue with around 250 lines in the anonymous editor Aug 25, 2016 at 18:52

I just encountered a very similar problem using MavensMate/ APEX Scripting / ExecuteAPEX.

I have some code I wanted to fiddle with in APEX Anonymous before making a formal class.

As it got to moderate size (156 lines, 11626 characters per the wc command), I began to get some baffling (and maddening) behavior. From one edit to the next it would go from running fine to running for an infinite time. No error, just never finished.

If I run it in dev con I get a non-helpful error flashing up: "Execute Anonymous Error Line: undefined, Column: undefined Response to EXEC was:.HTTP CODE[413]"

The end of the code has a large line commented with /* */, and I think that if I exceed the character limit it pushes the */ off the end, so the comment is open-ended and the code does not compile (from the user perspective it just spins).

For grins I kept a copy of the code which has this line: //If this line is duplicated below, boom

And if you do, it does. I am moving the code to a class.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .