salesforce_execute_anonymous
Execute anonymous Apex code in Salesforce to perform data operations, debug logs, or manage records when specific tools are unavailable. Requires valid Apex code and returns execution results with optional log levels.
Instructions
Execute anonymous Apex code in Salesforce.
Examples:
- Execute simple Apex code: { "apexCode": "System.debug('Hello World');" }
- Execute Apex code with variables: { "apexCode": "List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 5]; for(Account a : accounts) { System.debug(a.Name); }" }
- Execute Apex with debug logs: { "apexCode": "System.debug(LoggingLevel.INFO, 'Processing accounts...'); List<Account> accounts = [SELECT Id FROM Account LIMIT 10]; System.debug(LoggingLevel.INFO, 'Found ' + accounts.size() + ' accounts');", "logLevel": "DEBUG" }
Notes:
- The apexCode parameter is required and must contain valid Apex code
- The code is executed in an anonymous context and does not persist
- The logLevel parameter is optional (defaults to 'DEBUG')
- Execution results include compilation success/failure, execution success/failure, and debug logs
- For security reasons, some operations may be restricted based on user permissions
- This tool can be used for data operations or updates when there are no other specific tools available
- When users request data queries or updates that aren't directly supported by other tools, this tool can be used if the operation is achievable using Apex code
Input Schema
Name | Required | Description | Default |
---|---|---|---|
apexCode | Yes | Apex code to execute anonymously | |
logLevel | No | Log level for debug logs (optional, defaults to DEBUG) |