Loading
Enhance Salesforce with Code
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Executing Anonymous Apex Code

          Executing Anonymous Apex Code

          The Developer Console allows you to execute Apex code as another way to generate debug logs that cover specific application logic.

          User Permissions Needed
          To execute anonymous Apex in user context or system mode: “API Enabled” and “Author Apex”

          The Execute Anonymous Apex tool in the Developer Console runs the Apex code you enter using ExecuteAnonymous and generates a debug log with the results of the execution.

          1. Click Debug | Open Execute Anonymous Window to open the Enter Apex Code window.
            Enter Apex Code window
          2. Enter the code you want to run in the Enter Apex Code window or click Triangle icon to open the code editor in a new browser window. To automatically open the resulting debug log when execution is complete, select Open Log.
            Note
            Note You can't use the keyword static in anonymous code.
          3. Execute the code:
            Important
            Important Every time you run ExecuteAnonymous, the code and its references are compiled. For repetitive calls, we strongly recommend you use compiled classes, such as Apex REST endpoints.
            1. To execute all code in the window, click Execute or CTRL+E.
            2. To execute only selected lines of code, select the lines and click Execute Highlighted or CTRL+SHIFT+E.
          4. If you selected Open Log, the log automatically opens in the Log Inspector. After the code executes, the debug log will be listed on the Logs tab. Double-click the log to open it in the Log Inspector.
          5. To execute the same code again without making changes, click Debug | Execute Last. If you want to modify the code, click Debug | Open Execute Anonymous Window, to open the Enter Apex Code window with the previous entry.
           
          Loading
          Salesforce Help | Article