A hard-coded ID is a Salesforce record ID typed directly into metadata: an Apex class that checks for a specific record type ID, a flow that assigns records to a specific user ID, a validation rule that compares against a specific profile ID, or a formula that refers to a specific record. Hard-coded IDs work in the org where they were written and then break when the metadata moves, because the same record usually has a different ID, or does not exist at all, in another org.
Why Hard-Coded IDs Cause Problems
- Deployment failures and silent errors. After a deployment or sandbox refresh, the ID points to nothing or to the wrong record, and automation fails or behaves incorrectly without an obvious error.
- Hidden dependencies. A literal ID is not a named reference, so dependency tools and deletion checks do not see the connection.
- Maintenance cost. Every new environment needs manual edits to the same metadata.
How to Approach Hard-Coded IDs
- Scan the metadata for 15- and 18-character Salesforce IDs in code, flows, formulas, and configuration.
- Identify what each ID refers to. The first three characters of an ID, the key prefix, identify the object, and a lookup in the org identifies the record.
- Fix broken references first. IDs that point to nothing in the current org are already failing.
- Replace IDs with names. Use developer names, custom metadata, custom labels, or queries by name, so the metadata works in every org.
- Scan again before each deployment to catch new hard-coded IDs.
How Snapshot Helps
- Hard Coded IDs Report: finds Salesforce IDs typed directly into metadata. Each row shows the distinct ID, the containing asset or element, the Prefix Object, what the ID Refers To, the Resolution, and Occurrences. IDs are matched to assets in the snapshot and, with Lookup Org Records enabled, to records and metadata in the org. Missing In Org and Unknown Prefix flag broken references, and Prefix Only means existence could not be confirmed. Show Usage displays the surrounding text. Use a regular snapshot, not a developer project.
- Impact Analysis Report: shows the named references around an asset, which complements the literal ID findings.
A resolved ID does not prove the metadata will work in another org, and the scan does not run automation or apply fixes.
Metadata Types Involved
-
ApexClass: code that compares or assigns IDs. -
Flow: flows that assign owners, record types, or queues by ID. -
ValidationRule: formulas that compare against specific IDs. -
CustomMetadata: a deployable place to store configuration values instead of IDs. -
CustomLabels: named text values that code and pages can reference.
Common Questions
Why do IDs differ between orgs?
Each org assigns its own IDs when records and many configuration items are created. Records created after a sandbox is copied, and anything created separately in each org, get different IDs.
What should replace a hard-coded record type ID?
Look up the record type by developer name at run time, or store the developer name in custom metadata, so the same metadata works in every org.
Can I tell what an unknown ID refers to?
The three-character key prefix identifies the object type. Looking the ID up in the org identifies the specific record, if the record still exists.