get_object_fields
Retrieve field names, labels, and types for any Salesforce object by specifying the object name, simplifying metadata access for Salesforce integrations.
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:47-73 (handler)Core handler implementation in SalesforceClient: retrieves, filters, caches, and returns JSON of object fields using Salesforce describe() API.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:124-137 (registration)Tool registration in list_tools(): defines name, description, and input schema for 'get_object_fields'.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:330-342 (handler)MCP @server.call_tool() handler: dispatches 'get_object_fields' tool calls to SalesforceClient method 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}", ) ]