Record ID
A Record ID is the unique identifier Salesforce assigns to every record it stores.
Definition
A Record ID is the unique identifier Salesforce assigns to every record it stores. It is a 15-character case-sensitive string that the platform generates the moment a record is inserted, and it never changes for the life of that record. The first three characters of the ID are the object key prefix and tell you what type of record it is (001 for Account, 003 for Contact, 006 for Opportunity, 500 for Case). The remaining 12 characters are a base-62 encoded identifier inside that object's table.
Record ID is what every Salesforce URL, API call, formula reference, and integration uses to point at a specific row. Salesforce also exposes an 18-character version of the same ID that adds a three-character checksum suffix; the 18-character form is case-insensitive and is what you use anywhere case sensitivity might be lost (Excel, Outlook, some external systems). The two forms point at the same record, and the platform accepts either in URLs and API calls.
Why every Salesforce integration eventually argues about the 15 vs 18 character ID
Anatomy of a 15-character ID
The first three characters of a Record ID are the object key prefix. 001 is Account, 003 is Contact, 005 is User, 006 is Opportunity, 500 is Case, 00Q is Lead, 00T is Task, and so on. The next two characters identify the pod the org runs on. The remaining ten characters are a unique sequence per record within that object. Because the characters are case-sensitive base-62 (0-9, a-z, A-Z), an upper-case A and a lower-case a refer to different records. This is the single most common source of integration bugs with Salesforce.
Why 18 characters exists
Salesforce added the 18-character ID because case-insensitive systems (Excel, Outlook, parts of the old XML SOAP toolkit, some ERP staging tables) could not round-trip a 15-character ID safely. Two distinct records like 0015000000Abcde and 0015000000ABCDE collapsed into one row when an integration uppercased everything. The 18-character form appends three checksum characters that encode the case pattern of the first 15. Salesforce treats both forms as equivalent in URLs and API calls, but external systems should always store the 18-character form to avoid case-folding collisions.
Object key prefix as a routing hint
Because the first three characters identify the object, you can write an Apex method or a formula that branches on object type from the ID alone, without a SOQL query. The Schema class exposes getKeyPrefix() on every SObjectType to look up the prefix programmatically. Lightning record pages use this same prefix to route a URL like /lightning/r/0064x0000005abc to the correct Opportunity layout. Custom objects get a 3-character prefix starting with a lowercase a (a00, a01, ...) assigned at creation time.
Record IDs in formulas, URLs, and SOQL
Inside a formula, the Id merge field returns the 15-character ID. A common pattern is HYPERLINK("/" + Id, "Open record"), which builds a clickable internal link. In SOQL, the Id column always returns 18 characters via the REST API and 15 via the older SOAP enterprise WSDL by default. In Visualforce and LWC, the Id type is always serialized as the 18-character form. Apex's Id type accepts either as input and prints the 18-character form when cast to String.
Reusing IDs after deletion
Salesforce never reuses a Record ID, even after a hard delete. The ID is permanently retired. This matters when integrations cache IDs as foreign keys to Salesforce records; a deleted-then-recreated record gets a new ID, and the integration must remap. Soft-deleted records (in the Recycle Bin) keep their original ID and resume use if undeleted. The IsDeleted column on every standard object marks soft-deleted rows, which is how the QueryAll API can still return them.
External IDs are not Record IDs
An External ID is a custom field marked unique that holds an identifier from another system (an SAP customer number, a Stripe charge ID). Salesforce indexes external IDs separately from the Record ID and lets you upsert by them through the API. They serve different purposes. The Record ID is Salesforce's own primary key; the External ID is a secondary key for cross-system reconciliation. Integration designs that confuse the two end up with brittle code that breaks on the first record that gets reparented or merged.
IDs across sandbox refreshes and org migrations
Record IDs are stable inside a single org, but they change across orgs. A sandbox refresh produces a new copy of every record with new IDs, even though the data content is identical. When you move metadata between sandbox and production via change sets or Bitbucket pipelines, hard-coded IDs in formulas, validation rules, or Apex break on landing. The standard fix is to use Custom Metadata Types or Custom Settings to hold environment-specific IDs, and to reference them by API name from code that needs to follow the data across orgs.
Convert and validate a Record ID
Find, copy, and convert a Record ID between its 15- and 18-character forms for use in URLs, API calls, and integration payloads.
- Locate the ID in the URL
Open the record in Lightning or Classic. The path includes the 15-character ID, for example /lightning/r/Account/0014x000004Pq1qAAC/view. Copy the segment that begins with the object key prefix.
- Use the developer console
Open the Developer Console, Debug, Open Execute Anonymous. Run System.debug([SELECT Id FROM Account LIMIT 1]). The 18-character ID prints in the log. This is the safest copy path for any integration script.
- Convert 15 to 18 via formula
Create a formula field of type Text using the CASESAFEID() function on Id. The field always returns the 18-character form. Use this on report exports and CSV downloads to give Excel users a safe identifier.
- Verify the key prefix
Match the first three characters against the object you expect. If they do not match, the integration has crossed wires somewhere. A quick prefix audit catches most mismatched-object bugs at the boundary instead of downstream.
- Test case sensitivity in the destination
If the receiving system (Excel, an Outlook plug-in, a flat file) might fold case, store the 18-character form. Round-trip one known ID through your pipeline and confirm it returns equal byte-for-byte before going live.
Case-sensitive. Used by the Salesforce UI and the legacy SOAP API. Safe inside Salesforce but unsafe in external systems that fold case.
Case-insensitive (the last 3 characters are a checksum). Safe everywhere. Default for REST API, LWC, and modern integrations.
Salesforce formula function that returns the 18-character form of any record Id. Useful in report-exported text fields.
Custom field marked Unique and External ID. Holds an outside-system identifier. Separate from the Record ID.
- Excel and many email clients fold case on Salesforce IDs. Always export the 18-character form, not the 15, when the destination might lowercase or uppercase the string.
- Record IDs change across orgs. Never hard-code an ID in Apex or a formula; reference Custom Metadata or a Custom Setting that holds the environment-specific value.
- The first three characters identify object type, but custom objects share the prefix range. Two custom objects in different orgs can have the same key prefix, so the prefix alone does not uniquely identify your object across orgs.
- Deleted records never have their IDs reused. If an integration sees an ID disappear from a query result, the record was soft-deleted or moved out of scope, not renumbered.
Trust & references
Cross-checked against the following references.
- Field Types: Record IDsSalesforce Developer Docs
- Salesforce Record ID LengthSalesforce Help
- Apex ID ClassSalesforce Developer Docs
Straight from the source - Salesforce's reference material on Record ID.
- Record ID ConceptsSalesforce Developer Docs
- Standard Object Key Prefix ListSalesforce Developer Docs
- External ID FieldsSalesforce Help
Hands-on resources to go deeper on Record ID.
About the Author
Dipojjal Chakrabarti is a B2C Solution Architect with 29 Salesforce certifications and over 13 years in the Salesforce ecosystem. He runs salesforcedictionary.com to help admins, developers, architects, and cert/interview candidates sharpen their fundamentals. More about Dipojjal.
Test your knowledge
Q1. What is a Record ID?
Q2. What's the difference between 15 and 18 characters?
Q3. What do the first three characters indicate?
Discussion
Loading discussion…