Skip to main content
Glama

get_object_fields

Retrieve field names, labels, and types for any Salesforce object to understand its data structure and integration requirements.

Instructions

Retrieves field Names, labels and types for a specific Salesforce object

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
object_nameYesThe name of the Salesforce object (e.g., 'Account', 'Contact')

Implementation Reference

  • MCP tool handler for 'get_object_fields': validates input arguments, invokes the SalesforceClient helper method, and returns the result formatted as MCP 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}",
            )
        ]
  • Core logic for retrieving and caching Salesforce object fields using describe() API, filtering specific field properties, and returning 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)
  • Registers the 'get_object_fields' tool with the MCP server via list_tools(), including description and JSON schema for input validation (requires 'object_name' string).
    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"],
        },
    ),

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/leilaabdel/MCP-Salesforce'

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