Home SALESFORCEAPEX How to get the Salesforce Object Name using Salesforce ID?

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

You may also like

Leave a Comment