How to fix MALFORMED_ID in Salesforce deployments
A value passed where Salesforce expects a record ID isn't a valid ID at all, not just the wrong one.
Surfaces during: runtime DML and SOQL, in data loads, integrations, and Apex testsWhat it means
MALFORMED_ID means the value Salesforce received isn't a syntactically valid record ID: wrong length, invalid characters, or a value that isn't an ID at all. This differs from INVALID_ID_FIELD, where the ID is well-formed but points to the wrong record or object; MALFORMED_ID means the string itself is broken.
A valid Salesforce ID is always 15 or 18 alphanumeric characters starting with a three-character object key prefix; anything shorter, longer, or containing characters outside [A-Za-z0-9] fails this check before Salesforce ever attempts to resolve it to a record.
Common causes
The fix
- Validate ID format before useCheck that any dynamically built or imported ID is exactly 15 or 18 alphanumeric characters before passing it into DML or a lookup.
Boolean looksLikeId = idValue != null && idValue.isAlphanumeric() && (idValue.length() == 15 || idValue.length() == 18); - Re-export data load files without reformattingExport CSVs as plain text and disable spreadsheet auto-formatting that can strip or alter ID columns.
- Never hardcode placeholder IDs in test setupQuery for a real record ID in test setup instead of assigning a literal string to an Id-typed variable.
How Serpent prevents this
Serpent AI resolves references by business key instead of raw ID strings when moving changes between environments, so a malformed or hardcoded ID never reaches a target org's deploy. See the Salesforce deployment error library.

Prevention
Related errors
MALFORMED_ID, answered
Start free. No credit card, no install, no commitment.
Set up in under 15 minutes. No DevOps hire needed.
