Skip to main content
Glama
JereSalguero30

Salesforce MCP Server

salesforce_execute_anonymous

Execute anonymous Apex code in Salesforce to run custom logic, data queries, or updates when standard tools lack support. Returns debug logs and execution results.

Instructions

Execute anonymous Apex code in Salesforce.

Examples:

  1. Execute simple Apex code: { "apexCode": "System.debug('Hello World');" }

  2. Execute Apex code with variables: { "apexCode": "List accounts = [SELECT Id, Name FROM Account LIMIT 5]; for(Account a : accounts) { System.debug(a.Name); }" }

  3. Execute Apex with debug logs: { "apexCode": "System.debug(LoggingLevel.INFO, 'Processing accounts...'); List 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

TableJSON Schema
NameRequiredDescriptionDefault
apexCodeYesApex code to execute anonymously
logLevelNoLog level for debug logs (optional, defaults to DEBUG)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of disclosing behavior. It states that code is executed in an anonymous context, does not persist, and returns compilation/success/failure and debug logs. It also mentions security restrictions. However, it does not explicitly warn about potential persistent side effects from DML operations (e.g., updates), which would be a useful caution for an execution tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is moderately long but well-structured with examples and notes. While some notes repeat schema details (e.g., 'apexCode parameter is required' and 'logLevel parameter is optional'), the examples add practical value and the additional notes (persistence, execution results, security) are informative. Every section earns its place, but it could be slightly more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with only two params and no output schema, the description is thorough. It covers purpose, examples for multiple levels of complexity, execution results, security considerations, and use cases. It clearly explains fallback scenarios relative to sibling tools. This is complete enough for an agent to decide when and how to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema already covers both parameters with descriptions. The description adds value by providing concrete examples of apexCode usage, explaining that logLevel defaults to DEBUG, and noting the apexCode parameter is required. This goes beyond the schema's basic descriptions and helps the agent understand practical usage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function: 'Execute anonymous Apex code in Salesforce.' It specifies the resource (Apex code) and the action (execute anonymously). It also distinguishes itself from siblings by noting it's a general fallback for data operations or queries not directly supported by other tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use the tool: 'when there are no other specific tools available' and for requests 'not directly supported by other tools.' It does not name specific alternative tools or explicitly state when not to use it, but the context is clear. Security restrictions are also noted.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JereSalguero30/mcp-server-salesforce'

If you have feedback or need assistance with the MCP directory API, please join our Discord server