apex_execute
Call Salesforce Apex REST endpoints directly by specifying the endpoint and HTTP method (GET, POST, PATCH, DELETE). Supports sending data for POST/PATCH requests to interact with Salesforce APIs.
Instructions
Executes an Apex REST request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | The Apex REST endpoint to call (e.g., '/MyApexClass') | |
| data | No | Data for POST/PATCH requests | |
| method | No | The HTTP method (default: 'GET') | GET |
Implementation Reference
- src/salesforce/server.py:431-447 (handler)Handler implementation for the 'apex_execute' tool. Extracts 'action', 'method', and 'data' parameters, performs validation, calls sf_client.sf.apexecute to execute the Apex REST request, and returns the result as formatted JSON text content.elif name == "apex_execute": action = arguments.get("action") method = arguments.get("method", "GET") data = arguments.get("data") if not action: raise ValueError("Missing 'action' argument") if not sf_client.sf: raise ValueError("Salesforce connection not established.") results = sf_client.sf.apexecute(action, method=method, data=data) return [ types.TextContent( type="text", text=f"Apex Execute Result (JSON):\n{json.dumps(results, indent=2)}", ) ]
- src/salesforce/server.py:256-277 (schema)Input JSON schema for the 'apex_execute' tool defining parameters: 'action' (required string), 'method' (optional enum: GET/POST/PATCH/DELETE, default GET), 'data' (optional object).inputSchema={ "type": "object", "properties": { "action": { "type": "string", "description": "The Apex REST endpoint to call (e.g., '/MyApexClass')", }, "method": { "type": "string", "description": "The HTTP method (default: 'GET')", "enum": ["GET", "POST", "PATCH", "DELETE"], "default": "GET", }, "data": { "type": "object", "description": "Data for POST/PATCH requests", "properties": {}, "additionalProperties": True, }, }, "required": ["action"], },
- src/salesforce/server.py:253-278 (registration)Registration of the 'apex_execute' tool in the list_tools() function decorated with @server.list_tools(), including name, description, and input schema.types.Tool( name="apex_execute", description="Executes an Apex REST request", inputSchema={ "type": "object", "properties": { "action": { "type": "string", "description": "The Apex REST endpoint to call (e.g., '/MyApexClass')", }, "method": { "type": "string", "description": "The HTTP method (default: 'GET')", "enum": ["GET", "POST", "PATCH", "DELETE"], "default": "GET", }, "data": { "type": "object", "description": "Data for POST/PATCH requests", "properties": {}, "additionalProperties": True, }, }, "required": ["action"], }, ),