Subscribe to my full feed.

This is Part 2 of 5 in my series on converting 15-character Salesforce IDs seen in the Salesforce UI into the 18-character IDs seen in results from the Data Loader and API calls. You can start at Part 1 here.

It turns out that learning the "secret formula" for converting a 15-character ID into an 18-character ID is as easy as searching for "how do I convert an ID" in the Salesforce help screen. The resulting solution accurately describes the process, although it isn't exactly written in a way that makes it immediately clear how the process works (no "ah ha!" moments here...).

Luckily, they include an example, which I will share (in a simple form) below.

Side Note: If anyone is reading this, and needs to convert the 18-character ID BACK to the 15-character ID, there is no algorithm required - just chop off the last 3 characters! There - I just saved someone the pain of trying to do the steps below in reverse... ;)

Step 1: Get the 15-character version of the ID, in this case "500x000000003TR"

Step 2: Convert to 1's and 0's. Rule: Capital letter get's a 1, anything else gets a 0.
500x000000003TR becomes
000000000000011

Step 3: Split into 3 chunks of 5 characters, and REVERSE the order of the characters in each group:
00000 becomes Chunk 1: 00000
00000 becomes Chunk 2: 00000
00011 becomes Chunk 3: 11000

Step 4: Use the key below to convert each chunk to a Letter (you can use the chunk, or convert the chunk from binary into decimal - whatever you prefer)
Binary Decimal Matching
Chunk Chunk Letter
00000 0 A
00001 1 B
00010 2 C
00011 3 D
00100 4 E
00101 5 F
00110 6 G
00111 7 H
01000 8 I
01001 9 J
01010 10 K
01011 11 L
01100 12 M
01101 13 N
01110 14 O
01111 15 P
10000 16 Q
10001 17 R
10010 18 S
10011 19 T
10100 20 U
10101 21 V
10110 22 W
10111 23 X
11000 24 Y
11001 25 Z
11010 26 0
11011 27 1
11100 28 2
11101 29 3
11110 30 4
11111 31 5

In our case:
Chunk 1(00000) becomes "A"
Chunk 2(00000) becomes "A"
Chunk 3(11000) becomes "Y"

Step 5: Add the converted chunks, in order, to the end of the original 15-character ID:
500x000000003TR becomes 500x000000003TRAAY

And there it is. The non-case-sensitive version of 500x000000003TR is 500x000000003TRAAY.

Salesforce is very friendly about using either version of the ID - you can use the 15-char or the 18-char version anywhere - in the URL, in the Data Loader, via the API, etc.

But for my IT group, who stores SFDC IDs in a non-case-sensitive table (try getting them to change that!), it's the 18 character version or nothing.

And that's where babies 18-character IDs come from.

Stay tuned - in Part 3, we'll turn the process above into Apex Code!

0 comments:

Post a Comment