I'm having trouble in some code trying to dynamically determine the object type of a CaseComment object is APEX.

This can be reproduced in anonymous APEX using this sample

Id myId = '00aS00000027nijIAA';

SObjectType childObjectType = myId.getSObjectType();

Error message

System.SObjectException: Cannot locate Apex Type for ID: 00aS00000027nijIAA

I haven't found this as a known issue but could easily have missed it, or not known where to look. If I'm doing something wrong please let me know.

I tried searching for others having the same problem but haven't found anything yet.

I would like to avoid writing workarounds for just this object type when it works fine for more common objects.

  • My case is with Salesforce R&D right now. I'll post back once I receive a formal answer. Commented Apr 2, 2014 at 19:49

3 Answers 3


The final resolution from Salesforce.com support, case number 10306483:

"When you call the getSObjectType() Apex method to an Id object to get an sObjectType from the Id, we internally call the method and try to get a Type from an entity info returned from it. And in this method call, an entity info is retrieved from a key prefix of the specified Id. However, if the key prefix points to a template entity, the method call returns null since template entities cannot reveal their entity infos. In case of CaseComment, it shares its key prefix with CaseObjectComment. So, when we try to obtain the entity info using an Id of a CaseComment, we do that through CaseObjectComment. But, since CaseObjectComment is a template entity, we cannot get its entity info. It causes the issue.

IdeaComment shares its key prefix with CaseObjectComment, too. So the same issue occurs when calling getSobjectType() Apex method to an Id of an IdeaComment."

  • Did they agree to fix this in the future, or are they going to leave it as is? Commented Apr 4, 2014 at 20:03
  • It didn't sound like it will be considered a bug. I think to get it fixed I will need to submit an idea to the success community. I have not yet done so at this time. Commented Apr 7, 2014 at 19:31
  • Thanks for looking into this. Just in case anyone else sees this I ran into this issue with the a CustomShare object, which shares its id prefix with any other CustomShare object. SALESFORCE OYYY. Commented Mar 31, 2017 at 18:34

I replicated the issue in my org.

getSObjectType has no documented limitiations in terms of which object it does or does not work for.

So it looks like a bug in SF indeed. You are going to need a workaround for this (and maybe other?) objecttypes as long as it is not resolved.

  • 1
    I was also able to reproduce it by creating a CaseComment and then using the Id in the code in the Question.
    – BarCotter
    Commented Mar 10, 2014 at 14:40
  • Thanks for confirming. I've opened a case with Salesforce and will report back. Commented Mar 10, 2014 at 17:05

I have the same issue: Id.getSObjectType() does not work if Id is from a CaseComment object. My workaround is to use getSObjectType() directly on the object, not the Id. This works fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .