I have to object Student and Student Object, based on student id passed throug query string I am retriving Student data using query, I have observed that, for the Student detail field the id is getting appended with some value, due to which,when I query Student detail object to get record based on Student detail id I am getting no records, because Id does not match. Can anyone please answer why this is Id is getting appended. For example Query result- StudentDetail__c=a08j0000003lYUTAA2 Actual id-a08j0000003lYUT
There is a lot of information out there on 15 vs 18 character ID's. Basically and ID is case sensitive so when it is displayed as a string (console, export, etc) the last 3 characters are append by SF so it can convert it back to a 15 character case sensitive ID.
They can be used interchangeably so if you are having issues it is most likely because of that.
To illustrate you can execute this is dev console and it will work fine
String idstring; Account a = [Select ID From Account limit 1]; idString = a.id; system.debug(logginglevel.error,idstring); //Notice the extra characters Account b = [Select ID From Account where ID = :idstring]; system.assertEquals(a.id,b.id);
Here's what is happening behind the scenes to arrive at the 3-characters being appended to your 15-character Id provided (image below). These 3 additional characters are added to ensure legacy systems (which commonly don't use case-sensitive Ids) are able to distinguish a08j0000003lYUT from a08j0000003lyUT (lowercase 'y'). Appending the three characters to the 15-character Ids will now yield the following 18-character Ids (also known as 'Case Safe Ids'):
To any system, these are now both unique in proper-case, lower-case, and upper-case.
Salesforce.com, however, will recognize both 15- and 18-character Ids since it's engines use case-sensitive Ids.