Utility functions for validating Salesforce IDs, work item names, and escaping SOQL strings safely.
// Source: https://github.com/salesforcecli/mcp | License: Apache-2.0 | Copyright 2025 Salesforce, Inc
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Utility functions for safe SOQL query construction
*/
/**
* Validates that a string is a valid Salesforce ID (15 or 18 characters).
* Returns true if valid, false otherwise.
*/
export function isValidSalesforceId(id: string): boolean {
if (typeof id !== 'string') {
return false;
}
// Salesforce IDs are either 15 or 18 characters, alphanumeric
const trimmed = id.trim();
const idPattern = /^[a-zA-Z0-9]{15}$|^[a-zA-Z0-9]{18}$/;
return idPattern.test(trimmed);
}
/**
* Escapes single quotes in a string for use in SOQL queries.
* Throws an error if the value contains SQL injection att
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key