Reply
Newbie
efazendin
Posts: 2
Accepted Solution

GetUserInfoResult.getOrganizationId does not equal OrgID

[ Edited ]

I'm using the partner.wsdl to make a soap request from Java to the API to get information about a user based on their session id.  One of the things I'm retrieving is an Org ID to make sure its within a known and trusted set.  Just recently it seems that something may have changed with what is returned from the getOrganizationId() call.  The value returned no longer seems to match the Org ID listed in Salesforce.com under Setup > Company Information.  I am now seeing 3 characters appended to the valid org id string; EA0 in one case and EA2 in another.  Has anyone else seen this? 

Message Edited by efazendin on 06-24-2009 04:36 PM
Regular Contributor
cvj
Posts: 14

Re: GetUserInfoResult.getOrganizationId does not equal OrgID

Salesforce.com Record Ids can be either 15 characters (case sensitive) or 18 characters (case insensitive).  You can remove the last 3 characters if you are trying to compare an 18 character org id to a 15 character org id assuming you are also comparing the case of the characters in the id.

 

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. Construct 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.

Newbie
efazendin
Posts: 2

Re: GetUserInfoResult.getOrganizationId does not equal OrgID

CVJ,

Thanks for the reply.  Are the 18 character IDs new, or is this something I just hadn't run into previously? 

Visitor
david_padbury
Posts: 1

Re: GetUserInfoResult.getOrganizationId does not equal OrgID

I've just had to implement the logic for converting 15 char to 18 char identifiers as described by cvj in JavaScript. I thought i'd post it here in case anyone else happens to find this useful...

 

function convertToCaseInsensitiveId(id) {
    var hash = '';
    for (var c = 0; c < 3; c++) {
        var h = 0;
        for (var i = 0; i < 5; i++) {
            var ch = id.charCodeAt(i + c * 5);
            if (ch >= 65 && ch <= 91) h += Math.pow(2, i);
        }
        hash += String.fromCharCode(h > 26 ? h + 48 - 26 : h + 65);
    }
    return id + hash;
}

Contributor
joelmansford
Posts: 5

Re: GetUserInfoResult.getOrganizationId does not equal OrgID

I've just posted a version of David's code written in T-SQL (for MS SQL Server) on my blog here in case anyone finds it useful.
Contributor
d19engel
Posts: 5

Convert 18 digit Salesforce IDs in Google Spreadsheets with David Padbury's Script

David's Javascript is very useful because you can port that over to a Google Spreadsheet and use it like a "macro." 

 

 

  1. Open a Google Spreadsheet
  2. Select Tools > Scripts > Script Editor
  3. Paste David's function
  4. Save and exit the Google Apps Script Window
  5. Go back to the spreadsheet. Type a 15 digit salesforce ID in Cell A2
  6. In another spreadsheet cell, type convertToCaseInsensitiveId(A2)
And THAT, my friends, is how you convert 15 digit salesforce Ids to 18 digit sales force IDs without programming AND without upgrading Salesforce.

 

Contributor
d19engel
Posts: 5

Updated David_Padbury Script

A programmer named Stefan Kuehlechner made two updates to the David Padbury script (in bold).

 

function convertToCaseInsensitiveId(id) {
    var hash = '';
    for (var c = 0; c < 3; c++) {
        var h = 0;
        for (var i = 0; i < 5; i++) {
            var ch = id.charCodeAt(i + c * 5);
            if (ch >= 65 && ch < 91) h += Math.pow(2, i);
        }
        hash += String.fromCharCode(h > 25 ? h + 48 - 26 : h + 65);
    }
    return id + hash;
}

Contributor
d19engel
Posts: 5

Google Spreadsheets CONVERT 18 Digit Salesforce IDs

I hired a programmer to write the david_padburry script as a free, open source Google Spreadsheet script that is much easier to implement.

 

Here is an article that describes how to install and use the 15 to 18 digit Salesforce ID Converter from the open source Google Spreadsheet Script Gallery.