get_object_fields
Retrieve field names, labels, and data types for any Salesforce object to understand its structure and enable accurate data operations.
Instructions
Retrieves field Names, labels and types for a specific Salesforce object
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| object_name | Yes | The name of the Salesforce object (e.g., 'Account', 'Contact') |
Implementation Reference
- src/salesforce/server.py:56-82 (handler)Core handler function in SalesforceClient that fetches object fields using describe(), filters relevant info (label, name, updateable, type, length, picklistValues), caches results, and returns formatted JSON.def get_object_fields(self, object_name: str) -> str: """Retrieves field Names, labels and typesfor a specific Salesforce object. Args: object_name (str): The name of the Salesforce object. Returns: str: JSON representation of the object fields. """ if not self.sf: raise ValueError("Salesforce connection not established.") if object_name not in self.sobjects_cache: sf_object = getattr(self.sf, object_name) fields = sf_object.describe()['fields'] filtered_fields = [] for field in fields: filtered_fields.append({ 'label': field['label'], 'name': field['name'], 'updateable': field['updateable'], 'type': field['type'], 'length': field['length'], 'picklistValues': field['picklistValues'] }) self.sobjects_cache[object_name] = filtered_fields return json.dumps(self.sobjects_cache[object_name], indent=2)
- src/salesforce/server.py:133-146 (registration)Tool registration in list_tools() defining name, description, and input schema.types.Tool( name="get_object_fields", description="Retrieves field Names, labels and types for a specific Salesforce object", inputSchema={ "type": "object", "properties": { "object_name": { "type": "string", "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')", }, }, "required": ["object_name"], }, ),
- src/salesforce/server.py:136-145 (schema)JSON Schema for tool input validation: requires 'object_name' string.inputSchema={ "type": "object", "properties": { "object_name": { "type": "string", "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')", }, }, "required": ["object_name"], },
- src/salesforce/server.py:339-351 (handler)MCP server tool dispatcher handler that extracts arguments, calls the core get_object_fields, and formats response as TextContent.elif name == "get_object_fields": object_name = arguments.get("object_name") if not object_name: raise ValueError("Missing 'object_name' argument") if not sf_client.sf: raise ValueError("Salesforce connection not established.") results = sf_client.get_object_fields(object_name) return [ types.TextContent( type="text", text=f"{object_name} Metadata (JSON):\n{results}", ) ]