Skip to main content
Glama

salesforce_manage_object

Create or modify custom objects in Salesforce, including fields, labels, and sharing settings, to tailor data structures to specific business needs. Requires proper permissions for metadata changes.

Instructions

Create new custom objects or modify existing ones in Salesforce:

  • Create: New custom objects with fields, relationships, and settings

  • Update: Modify existing object settings, labels, sharing model Examples: Create Customer_Feedback__c object, Update object sharing settings Note: Changes affect metadata and require proper permissions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNoDescription of the object
labelNoLabel for the object
nameFieldFormatNoDisplay format for AutoNumber field (e.g., 'A-{0000}')
nameFieldLabelNoLabel for the name field
nameFieldTypeNoType of the name field
objectNameYesAPI name for the object (without __c suffix)
operationYesWhether to create new object or update existing
pluralLabelNoPlural label for the object
sharingModelNoSharing model for the object

Implementation Reference

  • The main handler function that implements the core logic for the 'salesforce_manage_object' tool, handling both 'create' and 'update' operations on Salesforce custom objects using the Metadata API.
    export async function handleManageObject(conn: any, args: ManageObjectArgs) { const { operation, objectName, label, pluralLabel, description, nameFieldLabel, nameFieldType, nameFieldFormat, sharingModel } = args; try { if (operation === 'create') { if (!label || !pluralLabel) { throw new Error('Label and pluralLabel are required for object creation'); } // Prepare metadata for the new object const metadata = { fullName: `${objectName}__c`, label, pluralLabel, nameField: { label: nameFieldLabel || `${label} Name`, type: nameFieldType || 'Text', ...(nameFieldType === 'AutoNumber' && nameFieldFormat ? { displayFormat: nameFieldFormat } : {}) }, deploymentStatus: 'Deployed', sharingModel: sharingModel || 'ReadWrite' } as MetadataInfo; if (description) { metadata.description = description; } // Create the object using Metadata API const result = await conn.metadata.create('CustomObject', metadata); if (result && (Array.isArray(result) ? result[0].success : result.success)) { return { content: [{ type: "text", text: `Successfully created custom object ${objectName}__c` }], isError: false, }; } } else { // For update, first get existing metadata const existingMetadata = await conn.metadata.read('CustomObject', [`${objectName}__c`]); const currentMetadata = Array.isArray(existingMetadata) ? existingMetadata[0] : existingMetadata; if (!currentMetadata) { throw new Error(`Object ${objectName}__c not found`); } // Prepare update metadata const metadata = { ...currentMetadata, label: label || currentMetadata.label, pluralLabel: pluralLabel || currentMetadata.pluralLabel, description: description !== undefined ? description : currentMetadata.description, sharingModel: sharingModel || currentMetadata.sharingModel } as MetadataInfo; // Update the object using Metadata API const result = await conn.metadata.update('CustomObject', metadata); if (result && (Array.isArray(result) ? result[0].success : result.success)) { return { content: [{ type: "text", text: `Successfully updated custom object ${objectName}__c` }], isError: false, }; } } return { content: [{ type: "text", text: `Failed to ${operation} custom object ${objectName}__c` }], isError: true, }; } catch (error) { return { content: [{ type: "text", text: `Error ${operation === 'create' ? 'creating' : 'updating'} custom object: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } }
  • Tool definition including name, description, and input schema for validating arguments to the 'salesforce_manage_object' tool.
    export const MANAGE_OBJECT: Tool = { name: "salesforce_manage_object", description: `Create new custom objects or modify existing ones in Salesforce: - Create: New custom objects with fields, relationships, and settings - Update: Modify existing object settings, labels, sharing model Examples: Create Customer_Feedback__c object, Update object sharing settings Note: Changes affect metadata and require proper permissions`, inputSchema: { type: "object", properties: { operation: { type: "string", enum: ["create", "update"], description: "Whether to create new object or update existing" }, objectName: { type: "string", description: "API name for the object (without __c suffix)" }, label: { type: "string", description: "Label for the object" }, pluralLabel: { type: "string", description: "Plural label for the object" }, description: { type: "string", description: "Description of the object", optional: true }, nameFieldLabel: { type: "string", description: "Label for the name field", optional: true }, nameFieldType: { type: "string", enum: ["Text", "AutoNumber"], description: "Type of the name field", optional: true }, nameFieldFormat: { type: "string", description: "Display format for AutoNumber field (e.g., 'A-{0000}')", optional: true }, sharingModel: { type: "string", enum: ["ReadWrite", "Read", "Private", "ControlledByParent"], description: "Sharing model for the object", optional: true } }, required: ["operation", "objectName"] } };
  • src/index.ts:97-114 (registration)
    Dispatch handler in the main switch statement that validates arguments and calls the handleManageObject function for the 'salesforce_manage_object' tool.
    case "salesforce_manage_object": { const objectArgs = args as Record<string, unknown>; if (!objectArgs.operation || !objectArgs.objectName) { throw new Error('operation and objectName are required for object management'); } const validatedArgs: ManageObjectArgs = { operation: objectArgs.operation as 'create' | 'update', objectName: objectArgs.objectName as string, label: objectArgs.label as string | undefined, pluralLabel: objectArgs.pluralLabel as string | undefined, description: objectArgs.description as string | undefined, nameFieldLabel: objectArgs.nameFieldLabel as string | undefined, nameFieldType: objectArgs.nameFieldType as 'Text' | 'AutoNumber' | undefined, nameFieldFormat: objectArgs.nameFieldFormat as string | undefined, sharingModel: objectArgs.sharingModel as 'ReadWrite' | 'Read' | 'Private' | 'ControlledByParent' | undefined }; return await handleManageObject(conn, validatedArgs); }
  • src/index.ts:35-45 (registration)
    Registration of the MANAGE_OBJECT tool in the list of available tools returned by ListToolsRequestSchema.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ SEARCH_OBJECTS, DESCRIBE_OBJECT, QUERY_RECORDS, DML_RECORDS, MANAGE_OBJECT, MANAGE_FIELD, SEARCH_ALL ], }));

Other Tools

Related Tools

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/SurajAdsul/mcp-server-salesforce'

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