Paul’s Salesforce Blog

What’s new with Salesforce?

Want to know an Object Type from an ID?

Posted by paulovery on November 20, 2015

Here’s how to do it in Salesforce APEX:

ID thisId = someId;
Schema.SObjectType objType = thisId.getSObjectType();

That’s it!  objType can now be used to identify the object type.

You can do comparisons with objType like this:

if (objType == ‘Quote’)….

or

if (objType == Quote.sObjectType)…

I hope you find this helpful!

Leave a comment