Skip to main content
Glama
usama-dtc

Salesforce MCP Server

by usama-dtc

salesforce_dml_records

Insert, update, delete, or upsert records in Salesforce using DML operations to manage data across objects like Accounts and Cases.

Instructions

Perform data manipulation operations on Salesforce records:

  • insert: Create new records

  • update: Modify existing records (requires Id)

  • delete: Remove records (requires Id)

  • upsert: Insert or update based on external ID field Examples: Insert new Accounts, Update Case status, Delete old records, Upsert based on custom external ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesType of DML operation to perform
objectNameYesAPI name of the object
recordsYesArray of records to process
externalIdFieldNoExternal ID field name for upsert operations

Implementation Reference

  • The main handler function that executes DML operations (insert, update, delete, upsert) on Salesforce records using jsforce connection, formats results with success/failure counts and error details.
    export async function handleDMLRecords(conn: any, args: DMLArgs) {
      const { operation, objectName, records, externalIdField } = args;
    
      let result: DMLResult | DMLResult[];
      
      switch (operation) {
        case 'insert':
          result = await conn.sobject(objectName).create(records);
          break;
        case 'update':
          result = await conn.sobject(objectName).update(records);
          break;
        case 'delete':
          result = await conn.sobject(objectName).destroy(records.map(r => r.Id));
          break;
        case 'upsert':
          if (!externalIdField) {
            throw new Error('externalIdField is required for upsert operations');
          }
          result = await conn.sobject(objectName).upsert(records, externalIdField);
          break;
        default:
          throw new Error(`Unsupported operation: ${operation}`);
      }
    
      // Format DML results
      const results = Array.isArray(result) ? result : [result];
      const successCount = results.filter(r => r.success).length;
      const failureCount = results.length - successCount;
    
      let responseText = `${operation.toUpperCase()} operation completed.\n`;
      responseText += `Processed ${results.length} records:\n`;
      responseText += `- Successful: ${successCount}\n`;
      responseText += `- Failed: ${failureCount}\n\n`;
    
      if (failureCount > 0) {
        responseText += 'Errors:\n';
        results.forEach((r: DMLResult, idx: number) => {
          if (!r.success && r.errors) {
            responseText += `Record ${idx + 1}:\n`;
            if (Array.isArray(r.errors)) {
              r.errors.forEach((error) => {
                responseText += `  - ${error.message}`;
                if (error.statusCode) {
                  responseText += ` [${error.statusCode}]`;
                }
                if (error.fields && error.fields.length > 0) {
                  responseText += `\n    Fields: ${error.fields.join(', ')}`;
                }
                responseText += '\n';
              });
            } else {
              // Single error object
              const error = r.errors;
              responseText += `  - ${error.message}`;
              if (error.statusCode) {
                responseText += ` [${error.statusCode}]`;
              }
              if (error.fields) {
                const fields = Array.isArray(error.fields) ? error.fields.join(', ') : error.fields;
                responseText += `\n    Fields: ${fields}`;
              }
              responseText += '\n';
            }
          }
        });
      }
    
      return {
        content: [{
          type: "text",
          text: responseText
        }],
        isError: false,
      };
    }
  • Tool definition object with name, description, and inputSchema for parameter validation.
    export const DML_RECORDS: Tool = {
      name: "salesforce_dml_records",
      description: `Perform data manipulation operations on Salesforce records:
      - insert: Create new records
      - update: Modify existing records (requires Id)
      - delete: Remove records (requires Id)
      - upsert: Insert or update based on external ID field
      Examples: Insert new Accounts, Update Case status, Delete old records, Upsert based on custom external ID`,
      inputSchema: {
        type: "object",
        properties: {
          operation: {
            type: "string",
            enum: ["insert", "update", "delete", "upsert"],
            description: "Type of DML operation to perform"
          },
          objectName: {
            type: "string",
            description: "API name of the object"
          },
          records: {
            type: "array",
            items: { type: "object" },
            description: "Array of records to process"
          },
          externalIdField: {
            type: "string",
            description: "External ID field name for upsert operations",
            optional: true
          }
        },
        required: ["operation", "objectName", "records"]
      }
    };
  • src/index.ts:36-47 (registration)
    Registration of the DML_RECORDS tool in the server's listTools response.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        SEARCH_OBJECTS, 
        DESCRIBE_OBJECT, 
        QUERY_RECORDS, 
        DML_RECORDS,
        MANAGE_OBJECT,
        MANAGE_FIELD,
        SEARCH_ALL,
        UPLOAD_REPORT_XML  // Add new tool to the list
      ],
    }));
  • src/index.ts:85-97 (registration)
    Dispatch handler in CallToolRequestSchema that validates arguments and calls the DML handler function.
    case "salesforce_dml_records": {
      const dmlArgs = args as Record<string, unknown>;
      if (!dmlArgs.operation || !dmlArgs.objectName || !Array.isArray(dmlArgs.records)) {
        throw new Error('operation, objectName, and records array are required for DML');
      }
      const validatedArgs: DMLArgs = {
        operation: dmlArgs.operation as 'insert' | 'update' | 'delete' | 'upsert',
        objectName: dmlArgs.objectName as string,
        records: dmlArgs.records as Record<string, any>[],
        externalIdField: dmlArgs.externalIdField as string | undefined
      };
      return await handleDMLRecords(conn, validatedArgs);
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses that operations are destructive (insert, update, delete, upsert) and mentions prerequisites like requiring Id for update/delete and external ID field for upsert. However, it doesn't cover authentication needs, rate limits, error handling, or what happens on partial failures.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear opening statement followed by bullet points for each operation and examples. Every sentence earns its place by providing essential information without redundancy. It's appropriately sized and front-loaded with the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 4 parameters, no annotations, and no output schema, the description is adequate but has gaps. It covers the basic operations and parameters but doesn't address return values, error conditions, or system-level constraints. Given the complexity of DML operations, more behavioral context would be beneficial.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds value by explaining what each operation does (e.g., 'upsert: Insert or update based on external ID field') and providing concrete examples that clarify parameter usage ('Insert new Accounts, Update Case status'). This enhances understanding beyond the schema's technical descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs data manipulation operations on Salesforce records with specific verbs (insert, update, delete, upsert) and distinguishes it from sibling tools like salesforce_query_records (read-only) and salesforce_describe_object (metadata). It explicitly names the resource (Salesforce records) and the action scope (data manipulation).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use each operation type (e.g., 'update: Modify existing records (requires Id)'), but doesn't explicitly state when to choose this tool over alternatives like salesforce_manage_object or salesforce_upload_report_xml. It gives operational guidance but lacks sibling differentiation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/usama-dtc/salesforce_mcp'

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