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

(231)

Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in IBM Austraila as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 9 Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply