The Hard Coded IDs report finds Salesforce record IDs that are typed directly into metadata assets such as Apex classes, Flows, Profiles, Page Layouts, and Visualforce pages. For every ID, the report shows what the ID points to: a metadata asset in the snapshot, a record in the org, or an object type based on the 3 character key prefix of the ID.
Hard coded IDs are a common source of deployment failures. Record IDs are different in every org, so an ID that works in production points to nothing after the metadata is deployed to a sandbox, and the reverse is also true. The report finds these IDs before a deployment, and also finds IDs that are already broken in the current org.
When To Use This Report
- Before a deployment between production and a sandbox.
- After a sandbox refresh, when automation stops working.
- During a technical debt review or a code review.
- When cleaning up references to deleted users, queues, record types, or records.
Open The Report
- Right-click a Metadata Snapshot item on the desktop.
- Select Hard Coded IDs under Optimize.
The report logs into the org with the credentials of the snapshot, so record IDs can be looked up in the org. If the login fails, an error message is shown and the report does not open. The report works with Regular Snapshots, not Developer Projects.
Select Metadata Tab
The left side of the tab lists every metadata type. Metadata types that are not in the snapshot are grayed out.
- Check the box next to each metadata type to include in the report.
- Type in the Quick Find box to locate a metadata type.
- Right-click the list to Check None, Check All Types, or Check Base Types.
- Select a metadata type to preview the hard coded IDs for that type in the table on the right.
Child types such as Custom Objects (Fields) and Custom Objects (Validation Rules) scan each child element on its own, so a hard coded ID is reported against the exact field, rule, or element that contains the ID.
Hold down the Escape key to cancel a long scan.
Display Report Tab
Open the Display Report tab to scan every checked metadata type. The report shows one table for each metadata type, with one row for every distinct ID found in an asset.
Display Options
- Show Links shows a link that opens the asset in Salesforce.
- Show Create Modify shows who created and last modified the asset, and when.
- Show Usage shows the text around each ID.
- Color Code shows broken references in red and resolved IDs in yellow.
- Clean Report hides tables that have no hard coded IDs.
- Lookup Org Records looks up IDs that are not in the snapshot by querying the org. Uncheck this option for a faster report that only uses the snapshot and the key prefix.
Use the menu on the right to sort by Asset Name, Hard Coded ID, Prefix Object, Resolution, Occurrences, Created By, Created Date, Last Modified By, or Last Modified Date.
Select Reports, Dashboards, or Summary to switch between the report tables, the charts, and the summary table.
Report Columns
| Column | Description |
|---|---|
| Folder Name | The folder of the asset, for folder based types such as Reports and Email Templates. |
| Asset Name | The asset that contains the hard coded ID. Child types show the Parent Asset here. |
| Element Name | The child element that contains the ID, for child types. Child types show the Child Asset here. |
| Hard Coded ID | The ID exactly as written in the asset, with 15 or 18 characters. |
| Prefix Object | The object type of the ID, based on the 3 character key prefix. |
| Refers To | The metadata asset or org record that the ID points to. |
| Resolution | How the ID was matched. See the table below. |
| Occurrences | The number of times the ID appears in the asset. |
| Usage Snippet | The text around the first occurrence of the ID. |
| Created By, Created Date, Last Modified By, Last Modified Date | Audit information for the asset. |
| Browser Link | A link that opens the asset in Salesforce. |
Resolution Values
| Resolution | Meaning |
|---|---|
| Snapshot Asset | The ID belongs to a metadata asset in the snapshot, such as a Flow, Apex Class, Profile, Custom Field, or Record Type. |
| Org Record | The ID belongs to a record in the org. The record name is shown in the Refers To column. |
| Org Metadata | The ID belongs to a Tooling API entity that exists in the org but is not in the snapshot. |
| Prefix Only | The object type is known from the key prefix, but the record was not looked up, or the lookup was not possible. |
| Missing In Org | The object type is known, but no record with this ID exists in the org. This is a broken reference. |
| Unknown Prefix | The key prefix does not match any object in the org. This is a broken reference. |
How IDs Are Found
- An ID has 15 or 18 letters and digits, with at least 3 digits and at least 1 letter.
- An 18 character ID must have a valid Salesforce checksum in the last 3 characters.
- A 15 character ID must match a snapshot asset or a known key prefix, which keeps ordinary words and numbers out of the report.
- The ID of the asset itself is skipped, and so are empty IDs such as 000000000000000AAA.
- Managed package assets and metadata buddy files that end in -meta.xml are skipped.
- 15 and 18 character versions of the same ID are reported as one ID.
Dashboards
- Metadata Types By Hard Coded IDs shows broken and resolved IDs for each metadata type.
- Metadata Types By Assets With Hard Coded IDs shows how many assets of each type contain hard coded IDs.
Summary
The summary table has one row for every metadata type in the report, and a Totals row at the bottom.
| Column | Description |
|---|---|
| Metadata Type | The metadata type that was scanned. |
| Total Assets | The number of assets scanned. |
| Assets With IDs | The number of assets that contain at least one hard coded ID. |
| Hard Coded IDs | The number of distinct IDs found. |
| Resolved IDs | IDs that point to a metadata asset, an org record, or a known object type. |
| Broken IDs | IDs that are Missing In Org or have an Unknown Prefix. |
| Assets With IDs % | The percent of assets that contain hard coded IDs. |
Export, Explain, And Schedule
- Right-click any table to export the report as CSV, Excel, PDF, or HTML.
- Right-click any table and select Explain Report Table to have the Intelligent Assistant summarize the findings and recommend fixes.
- Use the Schedule Report tab to run the report on a schedule. The condition If Hard Coded IDs Reported only sends the report when hard coded IDs are found.
Fixing Hard Coded IDs
- Record Types: look up the record type by Developer Name instead of by ID.
- Users, Queues, and Groups: store the Developer Name or Username in Custom Metadata, and query for the ID at run time.
- Profiles and Permission Sets: query by Name instead of by ID.
- Reports, Dashboards, and Documents: reference the Developer Name, or store the value in a Custom Label.
- Environment specific values: move the value into Custom Metadata or a Custom Label so each org can have the correct value.