function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFNewSFNew 

Know SObject type before Query/Retrieve

Hello,

          I am writing a client that updates our orgs data to SF. I am using API. I'd like to know if there is any way to know the object type from SF Id? I get the ID from our DB. I do not want to retrieve an SObject and then know that it is not what I wanted. Any help in this regard is greatly appreciated. Thanks all. 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

The DescribeSObject API call will return, amongst many values, the keyPrefix which is the 3 digit prefix for the specific sObject type. You can use the DescribeGlobal API, iterate through all the types and make corresponding DescribeSObject calls to build the list of keyPrefixes for all sObjects in your org. Then compare that list against your data Ids.

 

 

All Answers

aalbertaalbert

The DescribeSObject API call will return, amongst many values, the keyPrefix which is the 3 digit prefix for the specific sObject type. You can use the DescribeGlobal API, iterate through all the types and make corresponding DescribeSObject calls to build the list of keyPrefixes for all sObjects in your org. Then compare that list against your data Ids.

 

 

This was selected as the best answer
SFNewSFNew
Thanks much Albert. I'd try in that direction.