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 

Salesforce MVP | Lightning Champion | 16x Salesforce Certified | Application Architect | 6x Trailhead Ranger | Techforce Services | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*