You need to sign in to do that
Don't have an account?

Comparing 15 and 18 char long IDs
We have the situation that accessing SalesForce using webservices returns 18 char object IDs while using some of the other tools, eg. "Weekly Export Service", return 15 char IDs. What is the correct way in Java code to check if a 15 char ID refers to the same object as the 18 char ID? Is it simply a string prefix match or do we need to use some more complicated logic?
Hi malm,
Good question. The 18 character ID is constructed using a 15 character ID and adding 3 characters to the end (right hand side). These 3 additional characters cause the ID to be case-insensitive, where the 15 character ID is case sensitive. To obtain a 15 character ID from an 18 character id for purposes of case-sensitive comparison, you simple drop the last 3 characters of the 18 character ID (id.substring(0, 15) I think for java).
Message Edited by Ollie on 06-15-2004 12:31 PM
Ollie,
There are examples and an explanation in other threads. You can search on "18 char" or go to
For C#: http://forums.sforce.com/sforce/board/message?board.id=NET_development&message.id=535
For VB: http://forums.sforce.com/sforce/board/message?board.id=NET_development&message.id=536
Scot
Hi Ollie,
The api accepts 15 or 18 character ids, no conversion needed.
Here is some Java code that works for me.
=================================
private String normaliseSforceID(String id)
{
if (id == null || id.length() != 15)
{
return id;
}
String suffix = "";
for (int i = 0; i < 3; i++)
{
int flags = 0;
for (int j = 0; j < 5; j++)
{
char c = id.charAt(i * 5 + j);
if (c >= 'A' && c <= 'Z')
{
flags += 1 << j;
// System.out.println("j=" + j + " c=" + c + " flags=" + flags);
}
}
// System.out.println("flags=" + flags);
if (flags <= 25)
{
suffix += (char)('A' + flags);
}
else
{
suffix += (char)('0' + (flags-26));
}
}
return id + suffix;
}
Please help if possible.
Can I use the VB snipit to change the characters using an MS Access Module or do I need to find a full programming software. I am attempting to change the 15 char Id to the 18 char Id for a project I am doing and am limited to what I have access to.
If anyone can help I would appreciate it. I am new to all this.
Hello Jessica,
Yes, you should be able to use the VB code with MS Access. (I've used it often with Excel, which has much the same VBA facilities).
We have a weblink from SF that passes IDs to our ASP program. The IDs we get from the weblink is 15 digits. We then realized that this is case sensitive, i.e. we would get two ids that are same except the case. SQL server by default does not handle case sensitivity, so we started to have problem with SF IDs matches two rows in our SQL server DB, not good!
I found this online
http://vyaskn.tripod.com/case_sensitive_search_in_sql_server.htm
and it really helped, ended up just changing the collation on my column to case sensitive (method 4 in article) painless and way easier than convert ID back to 18.
I hope this helps someone.
function shortid2long($id)
{
if ($id === null || strlen($id) != 15)
{
return $id;
}
$suffix = "";
for ($i = 0; $i < 3; $i++)
{
$flags = 0;
for ($j = 0; $j < 5; $j++)
{
$c = substr($id, $i * 5 + $j, 1);
if ($c >= 'A' && $c <= 'Z')
{
$flags += 1 << $j;
# print("j=" . $j . " c=" . $c . " flags=" . $flags . "\n");
}
}
# print("flags=" . $flags . "\n");
if ($flags <= 25)
{
$suffix .= chr(ord('A') + $flags);
}
else
{
$suffix .= chr(ord('0') + ($flags-26));
}
}
return $id . $suffix;
}
I say, implement the 15-to-18-char conversion in a formula field and circumvent code entirely: http://tinyurl.com/15CharFix