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
Michael SMichael S 

Attachment parent type

How do I determine the type of an attachment's parent?

I know that I can call retrieve on all of referenceTo types in the type description, but is there an easier way?

DevAngelDevAngel

Hi Michael,

In API 4.0 there is a new attribute on the describeSObjectResult called keyPrefix.  This is a 3 character string that corresponds to the first 3 characters of an ID.  What this means is that you can determine the type of object that the attachment parent is by examining the first 3 characters of the ParentId and matching it with a prefix from a specific object describe.