8

When I'm trying to use Execute Anonymous with a large chunk of code, the following error pops up:

Line: undefined, Column: undefined Response to EXEC was : . HTTP CODE[414]

(414 stands for Request-URI Too Long) Sometimes I just need to remove a few tabs and line breaks to make the request short enough. Is there any way to bypass this limitation, or maybe there is another way to quickly execute a script without creating a new class?

2 Answers 2

12

The Developer Console is using the REST version of the Tooling API to perform the execute anonymous call. The length issue is a restriction of how the call encodes the apex into the URL.

/executeAnonymous/?anonymousBody= <url encoded body>

It is URL encoding your Apex onto the query string. Clearly there are limits to how long this can be.

I found a few viable alternatives.

  1. Create a temporary Apex class with the anon Apex in a static method. Then call that static method from Anon Apex. This works, but kind of defeats the purpose of anon apex.
  2. Use a tool (or direct call) that runs the Anonymous Apex via the SOAP API. The SOAP API puts the anonymous Apex in the SOAP POST request, so it doesn't care what the length is (beyond the Apex upper limits on class size).
  3. You can also run Anonymous Apex code via the older Apex SOAP API.
2
  • 4
    Thank you. I investigated upon #2 and found out that you can execute Apex through SOAP API using Workbench: workbench.developerforce.com/execute.php (it's in Utilities -> Apex Execute). And it works on really big chunks that Developer Console can't process.
    – mmm321321
    Jul 5, 2017 at 10:15
  • @mmm321321 workbench gives us COMPILE ERROR: Script too large for script exceeding 32K chars.
    – zaitsman
    Mar 3, 2021 at 0:48
2

You can also save the anonymous apex into a file and run it via the CLI. Sample command:

sfdx force:apex:execute -f "C:\temp\MyApexScript.apex" > result.log

1
  • Sadly i am still getting Script too large if my script exceeds 32K characters.
    – zaitsman
    Mar 3, 2021 at 0:46

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.