function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MaumanMauman 

Problem with ID Conversion - 15 to 18 Characters and Vice Versa

It appears as though the 18 character format, with the 3 added character mask characters sometimes treat numbers as uppercase.  For example:

The conversion from 18 to 15 is no problem, because numbers don't get converted:

00G30000000CIFAEA2 <- Original 18 character ID
4 0 27 <- Last 3 characters converted to their integer values
001000000011011 <- Conversion Mask... note that the last 0 is marked as "uppercase"
00G30000000CiFA <- The conversion succeeds though because 0 converted to uppercase is still 0.

However the conversion from 15 to 18 doesn't exactly work the same way:

00G30000000CiFA <- 15 character (case sensative form)
001000000001011 <- Assuming that all numbers are already lowercase, the mask is different.
4 0 11 <- Thus the integer values are different.
00G30000000CIFAEAL <- And finally the 18 character form is different as well, at least for the last character in this example.

My questions are:

1. Shouldn't the numbers always be treated as "lowercase", in which case there is a bug on the salesforce.com side of the API?

2. Is 00G30000000CIFAEAL treated the same way as 00G30000000CIFAEA2 if those values are sent back?  Are they ever sent back as 18 characters in the new API (sorry, I'm still trying to learn the new API)?

 

MaumanMauman
Wait it appears I forgot to invert the bits!
DevAngelDevAngel

Hi Mauman,

The conversion from 18 to 15 characters involves simply dropping the right 3 characters. 

00G30000000CIFAEA2 <- Original 18 character ID
E A 2 <- Last 3 characters (no conversion needed)

001000000011011 <- Conversion Mask... note that the last 0 is marked as "uppercase"
00G30000000CIFA <- The conversion succeeds though because 0 converted to uppercase is still 0.


 

MaumanMauman

I still have a problem converting 15 to 18.  I do not get the original 18 character ID.

There was a posting that had the text below, which appears to have been removed.

My new question is, is the following part of the conversion rule correct? 

|---------------|
|11010| 26 | 1  |
|---------------|
|11011| 27 | 2  |
|---------------|
|11100| 28 | 3  |
|---------------|
|11101| 29 | 4  |
|---------------|
|11110| 30 | 5  |
|---------------|
|11111| 31 | 6  |
|---------------|

Or should it be...

|---------------|
|11010| 26 | 0  |
|---------------|
|11011| 27 | 1  |
|---------------|
|11100| 28 | 2  |
|---------------|
|11101| 29 | 3  |
|---------------|
|11110| 30 | 4  |
|---------------|
|11111| 31 | 5  |
|---------------|

 

- - - - - - - - - - - - - - - - - - -

Here is the scoop on converting 15 to 18 character ids.

All case-sensitive ids are 15 chars.

To convert a 15 char case-sensitive id to an 18 char case-safe id follow these steps.

1.  Divide the 15 char into 3 chunks of 5 chars each.

2.  For each character give that position a value of 1 if uppercase, 0 otherwise (lowercase or number).

3.  Combine the bits from each chunk into a 5 bit integer where the rightmost bit is the most significant bit. This will yield a number between 0 and 31 for each chunk.

4.  Constuct an array that contains the sequence of capital letters A-Z and 0-5.

5.  Use the integer from each chunk to choose a character from the array.

6.  Append the resulting 3 characters, in chunk order, to the end of the 15 char id.

Example:
Convert 500x000000003TR to 18 character ID


              |---------|---------|---------|
chunks        | chunk 1 | chunk 2 | chunk 3 |
              |---------|---------|---------|
chunk index   |1|2|3|4|5|1|2|3|4|5|1|2|3|4|5|
              |---------|---------|---------|
id string     |5|0|0|x|0|0|0|0|0|0|0|0|3|T|R|
              |---------|---------|---------|
string bits   |0|0|0|0|0|0|0|0|0|0|0|0|0|1|1|
              |---------|---------|---------|

               |---------|
chunk index    |5|4|3|2|1|
               |---------|
chunk 1 bits = |0|0|0|0|0|
               |---------|

               |---------|
chunk index    |5|4|3|2|1|
               |---------|
chunk 2 bits = |0|0|0|0|0|
               |---------|

               |---------|
chunk index    |5|4|3|2|1|
               |---------|
chunk 3 bits = |1|1|0|0|0|
               |---------|

chunk 1 index = 0  = A
chunk 2 index = 0  = A
chunk 3 index = 24 = Y

Resulting ID: 500x000000003TRAAY

Bit to integer to character map
From right to left

|---------------|
|Bits |int |char|
|---------------|
|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  |
|---------------|

Message Edited by DevAngel on 05-18-2004 02:03 PM

DevAngelDevAngel

Hi Mauman,

Great catch!

It should be

|---------------|
|11010| 26 | 0  |
|---------------|
|11011| 27 | 1  |
|---------------|
|11100| 28 | 2  |
|---------------|
|11101| 29 | 3  |
|---------------|
|11110| 30 | 4  |
|---------------|
|11111| 31 | 5  |
|---------------|

 

Michael SMichael S

This is crazy!

Why are there two ID schemes in the first place?

 

Stuart.ax60Stuart.ax60

Hi,

Has anyone got any C# code that I can have that does the conversation descibed above.

Thanks in advance.

 

Stu

DevAngelDevAngel

Hi Mauman,

The conversion process for get a 15 char id from an 18 char id is simply lopping of the 3 characters on the right hand side of the string. 

ScotScot

Stu,

In case you haven't found it ... yes, there is a sample of C# code to convert 15 to 18 characters....

See http://forums.sforce.com/sforce/board/message?board.id=NET_development&message.id=535. The same thread also contains a good description of the 15/18 character ids, and an implementation in vba as well.