[SalesForce] SOQL where clause use 15-character ID

Can anyone confirm this: in a SOQL Where clause, when comparing an ID field to a 15-character string variable, the comparison works.

I didn't expect it to work, but it does and I am surprised. I can't find any documentation to confirm it. I thought 18-character ID was always in effect, and comparing 18-char ID to 15-char string would fail.

Example (Country__c is a lookup field):

String tmpID = 'a1he0000000EkAi';
Account acct = [select ID from Account where Country__c = :tmpID];

Best Answer

SOQL always accepts 15- and 18-character Id values. You can test this in any program-- data loader, excel connector, Apex Code. The system does this for compatibility with older code that may only use 15-character Id values. Apex Code specifically tries to cast a string to an Id automatically when used as a value on a field that expects an Id. It also tries to convert a string to an Id automatically if either operand in a comparison operation is an Id.