14

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

P.S. The code no longer works with the latest rev of Salesforce. I am not planning to make any updates as I no longer work with Salesforce. If anyone wants to fork the GitHub repo, it might live on.

AngryHacker
  • 1,481
  • 4
  • 24
  • 31

2 Answers2

21

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
Boris Bachovski
  • 16,216
  • 8
  • 47
  • 85
2

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.

Thanks!

cyberspy
  • 200
  • 2
  • 9
  • Your extension works perfectly. I would like to understand the logic behind conversion of 15 digit to 18 digit. We need to build this conversion process in a c# application – night crawler Aug 11 '21 at 20:31
  • This page explains it quite well: https://www.gammone.com/en/programming/how-to-convert-salesforce-id-from-15-to-18-chars – cyberspy Oct 21 '21 at 08:37