I have a 15 digit Sfdc ID, but I do not know which object it belongs to.

How can I find out which objects it belongs to and the convert it to 18 digits - all using SOQL?

P.S. I was annoyed at having to do this manually every single time, so I created a small app that detects 15 digits SFDC IDs and then automatically up converts them to 18 digits.

Video: https://www.youtube.com/watch?v=1xwd9WkcG10

Github: https://github.com/rgelb/SfdcIdUpConverter

Download: https://github.com/rgelb/SfdcIdUpConverter/releases/download/1.2/SfdcIdUpConverterSetup.exe

  • 1
    You can directly query the id of an sObject using the 15 char id value, and get the 18 char value returned. [SELECT Id FROM Account WHERE Id = '006V000000NT4kj'] will return the value '006V000000NT4kjIOU'. – battery.cord Sep 29 '15 at 13:26
  • Have a read of What are Salesforce ID's composed of?. The 15 and 18 character ID's can be used interchangeably in SOQL. – Daniel Ballinger Sep 29 '15 at 22:22

To convert it to 18 digits you can simply set it to an Id type variable:

Id someId = '001J000001eun1Q';

Which will automatically convert it for you:

system.debug(someId); // 001J000001eun1QIAQ

Then you can simply call the getSObjectType() method on the Id variable which will return the object name:

Schema.SObjectType objectType = someId.getSObjectType();
system.debug(objectType); // Account
  • But thats nit soql :) – zokito Sep 29 '15 at 6:25
  • You can't do that using SOQL, you have to use APEX. – Boris Bachovski Sep 29 '15 at 6:27
  • That's also correct – zokito Sep 29 '15 at 6:28
  • Didn't get the answer I would have liked...but just the system.debug trick is worth millions! – AngryHacker Sep 29 '15 at 16:45

I know this is an old post, but just in case it is useful to someone, if you want to do ad-hoc conversions of Id's, rather than programatically, then this Chrome extension makes it easy: https://chrome.google.com/webstore/detail/sf-15-to-18/cogllpmaoflgaekieefhmglbpgdgmoeg

FYI - I'm the developer. Please use the feedback form on the app if you'd like to suggest any improvements or additional functionality.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.