apex_execute
Execute Apex REST requests in Salesforce to call custom endpoints and manage data using HTTP methods like GET, POST, PATCH, and DELETE.
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') | |
| method | No | The HTTP method (default: 'GET') | GET |
| data | No | Data for POST/PATCH requests |
Implementation Reference
- src/salesforce/server.py:244-269 (registration)Registration of the apex_execute tool, including its description and JSON schema for input validation (action required, optional method and data).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"], }, ),
- src/salesforce/server.py:422-438 (handler)Handler for the apex_execute tool: validates inputs, calls Salesforce simple-salesforce library's apeXecute method on the action endpoint with optional method and data, and returns the JSON-formatted result.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)}", ) ]