+ Start a Discussion
efazendinefazendin 

GetUserInfoResult.getOrganizationId does not equal OrgID

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
Best Answer chosen by Admin (Salesforce Developers) 
cvjcvj

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.

All Answers

cvjcvj

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.

This was selected as the best answer
efazendinefazendin

CVJ,

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

david_padburydavid_padbury

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;
}

joelmansfordjoelmansford
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.
d19engeld19engel

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.

 

d19engeld19engel

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;
}

d19engeld19engel

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.

HzobirHzobir

Hi,

i'm writing a new connector to salesforce based on the toolkit 4.01. I need to chek if the user is on auto login ( the uesr have chek it in salesforce : User->My Setup->  My Softphone Setting is checked by the user to be in auto login),  in order to diplay the Login Form with the agent and extention value inside it from the code (Browser.connector Via the API): i can't find the way to get it because in:

GetUserInfoResult userInfo ( i haven't bthis property). So please can somebody help me...

 

Many Thanks.

Houcine