---
schema_version: "1"
id: 51b26e7d7d684b1357d71d7b2f0e29d2615658a9c321e09b3aab161c0d1fd9ce
title: Executing Anonymous Apex Code
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/code_dev_console_execute_anonymous.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.code_dev_console_execute_anonymous.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 2e35b5c6c61fb1567d1177b90c0372e31c6fb52df34ce67ac1422b499cc73c7d
description: The Developer Console allows you to execute Apex code as another way to generate debug logs that cover specific application logic.
products:
  - Salesforce Platform
release: "264"
---
# 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.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d6185e38">User
              Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d6185e38 ">To execute anonymous Apex in user context or system mode: </td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d6185e38 ">“API Enabled” and “Author
              Apex”</td>

          </tr>
        </tbody>
      </table>

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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/extend_code/images/code_dev_console_execute_anon_window.png)
2. Enter the code you want to run in the Enter Apex Code window or click ![Triangle icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/extend_code/images/code_dev_console_execute_anon_icon.png) 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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_note.png)
    
    Note You can't use the keyword `static` in anonymous code.
3. Execute the code:
    
    ![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_important.png)
    
    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.

#### See Also

- [Developer Console Debug Menu](https://help.salesforce.com/s/articleView?id=platform.code_dev_console_menu_debug.htm&release=264.0.0&type=5 "The Developer Console Debug menu allows you to manage your logs and execute anonymous Apex. It includes these options.")
- [Log Inspector](https://help.salesforce.com/s/articleView?id=platform.code_dev_console_view_system_log.htm&release=264.0.0&type=5 "The Log Inspector is a context-sensitive execution viewer in the Developer Console. It shows the source of an operation, what triggered the operation, and what occurred next. Use this tool to inspect debug logs that include database events, Apex processing, workflow, and validation logic.")
- [Debug Logs](https://help.salesforce.com/s/articleView?id=platform.code_debug_log.htm&release=264.0.0&type=5 "Use debug logs to track events that occur in your org. Debug logs are generated when you have active user-based trace flags, when you run Apex tests, and when executed code or API requests include debugging parameters or headers.")
- [Logs Tab](https://help.salesforce.com/s/articleView?id=platform.code_dev_console_tab_browser_logs.htm&release=264.0.0&type=5 "Use the Logs tab in the Developer Console to access logs that include database events, Apex processing, workflow, callouts, and validation logic.")