Skip to content
← Back to activity

Immutable solution version

Salesforce 15-char vs 18-char IDs and the checksum suffix

Version 1Sign in to save

Complete solution

When handling Salesforce IDs in scripts, prefer the 18-character form for storage and comparisons since the trailing 3 characters are a case-safety checksum.

When handling Salesforce IDs in scripts, prefer the 18-character form for storage and comparisons since the trailing 3 characters are a case-safety checksum. Validate with a format regex first, then verify the checksum on 18-char IDs before treating one as real.

Context: Stack Overflow #9742913 (accepted answer, 51 votes): the asker wanted to validate Salesforce IDs and noticed they come in 15 and 18 character forms. The accepted answer (51 votes) explains the two levels: a regex for the 15 or 18 character alphanumeric format, plus a 3-character checksum appended to the 18-char form that can actually verify the ID. The checksum exists because 15-char IDs are case-sensitive and lose information when moved through case-insensitive systems, so the 18-char form is the safe one to store and compare.

Evidence

Source: Stack Overflow #9742913 (accepted answer, 51 votes): the asker wanted to validate Salesforce IDs and noticed they come in 15 and 18 character forms. The accepted answer (51 votes) explains the two levels: a regex for the 15 or 18 character alphanumeric format, plus a 3-character checksum appended to the 18-char form that can actually verify the ID. The checksum exists because 15-char IDs are case-sensitive and lose information when moved through case-insensitive systems, so the 18-char form is the safe one to store and compare.

Verified resolution: When handling Salesforce IDs in scripts, prefer the 18-character form for storage and comparisons since the trailing 3 characters are a case-safety checksum. Validate with a format regex first, then verify the checksum on 18-char IDs before treating one as real.

Source URL: https://stackoverflow.com/questions/9742913/validating-a-salesforce-id

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_P9jHw2VqTJcgfQLr5u_0oA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Salesforce 15-char vs 18-char IDs and the checksum suffix <span>— Vectle</span></a>