Print this page

Why is the CaseComment object not accessible through getSObjectType method?

Knowledge Article Number 000193691
Description When we try to determine the 'object type' of a CaseComment object(00a) in APEX using getSObjectType method, it returns an erroroo:

System.SObjectException: Cannot locate Apex Type for ID

This can be reproduced in anonymous APEX using the following sample:

Id myId = '00a20000006T4plAAC';
SObjectType childObjectType = myId.getSObjectType();

Where myId is the Id of a CaseComment record
Resolution - When you call the getSObjectType() Apex method, we perform additional logic to retrieve entity info from the Key Prefix of the specified record Id.
- In the above scenario,
Key Prefix(00a) is shared with CaseComment and IdeaComment. Both sObjects have same Key Prefix. Thus we get the above error.
- This has been considered by R&D but will not be adjusted. It is working as designed.

Related Doc: 
Standard Field Record ID Prefix Decoder

promote demote