How to get the Salesforce Object Name using Salesforce ID?

To convert it to 18 digits you can simply set it to an Id type variable:
Id sfdcId = ‘001J000001eun1Q’;
Which will automatically convert it for you from 15digit to 18digits also please click the link for more details to convert from 15 digit to 18 digit salesforce id

system.debug(sfdcId); // 001J000001eun1QIAQ
Then you can simply call the getSObjectType() method on the Id variable which will return the salesforce object name, see below example:

Schema.SObjectType objectType = sfdcId.getSObjectType();
system.debug(objectType); // Account

Written by 

3x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published.

*