1

In SFDC we have methods to identify the type of ID

Sample code:

Id idType = '50011000002ZXX';               
Schema.sObjectType entityType = idType.getSObjectType();  
System.debug('ID belongs to:'+entityType); //ID belongs to: Case

Can we make use of the above methods in Java code using an API? How would one access these methods?

2 Answers 2

2

You can do this with either the SOAP or REST based versions of the Tooling API via EntityDefinition. There is a KeyPrefix field you can search on to find the specific match.

E.g.

Select Id,QualifiedApiName,KeyPrefix from EntityDefinition where KeyPrefix = '001'    
0

You need to check the generated code you are using to connect to Salesforce to determine if the Id type is a basic string type, or an actual type with methods associated with it.

From Metdata API Field Types:

"Note that most Web services tools, including .NET andWSC, map the ID simple type defined in the API WSDL (Enterprise or Partner) to a string. However, other tools generate a specific ID class to represent the ID simple type. Please consult your Web services toolkit documentation for more information."


See this (Near duplicate) for examples on how to determine the type of an id in non-apex code:

Determine sobject Type From Id Using SOAP API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.