[SalesForce] Running script in Execute anonymous in developer console gives execution failed error

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.

Thanks

Best Answer

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).