Why is CaseFeed.CreatedById Polymorphic?

A polymorphic lookup is, by definition, one where the SObjectType of the parent be multiple different values. That was the basis for how I compiled Polymorphic keys – definitive list?

However, a colleague stumbled across another “polymorphic” relationship via other means, namely a SOQL compile fail. Here’s the query:

SELECT CreatedBy.UserType FROM CaseFeed WHERE ...

And the error:

No such column ‘UserType’ on entity ‘Name’. If you are attempting to use a custom field, be sure to append the ‘__c’ after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

That error seems to clearly indicate this lookup is polymorphic.

Looking at the above data points, I was pretty shocked. CreatedBy is always a User, everywhere in the system. Just to sanity check, I ran the below script:

system.debug(CaseFeed.CreatedById.getDescribe().getReferenceTo());

The log output was as expected:

USER_DEBUG [1]|DEBUG|(User)

One line of investigation clearly indicates this field is not polymorphic. The other seems to indicate it is polymorphic. I’m strongly inclined to believe the former. Is there a platform bug or Known Issue here? Or is it expected behavior?

Answer

Looks like before Spring 12, CreatedBy field, on some objects, could be linked with User or SelfServiceUser object.

Found this 2010 blog post showing this screenshot:

enter image description here

SelfServiceUser is no longer available in new orgs as per doc here but since still active in older orgs, it remains polymorphic :

SelfServiceUser
Represents a Contact who has been enabled to use your organization’s Self-Service portal, where he or she can obtain online support.
Starting with Spring 12, the Self-Service portal isn’t available for new orgs. Existing orgs continue to have access to the Self-Service portal.

enter image description here

Attribution
Source : Link , Question Author : Adrian Larson , Answer Author : Shamina

Leave a Comment