I have triggers on FeedItem and FeedComment where I need to dynamically read a field on their respective Parents (ParentId).
For FeedItem I can do (for example):
FeedItem.Parent.get('Name');
But for FeedComment, which seems analogous in most respects
FeedComment.Parent.get('Name');
does not work, and the Force.com IDE Schema doesn't seem to help me out. Is there no way of getting for example the FeedComment Account Name without an SOQL query?
Best Answer
Of course, I found that to get the Parent info in a trigger context I had to use an SOQL query.
But then, I found that even
doesn't work, since it is a polymorphic field. See here for a description of the problem, and here for a potential solution in the future.
So, I use the method
FeedComment.ParentId.getSobjecttype()
to get the object to describe. A complication is that the field to dynamically get may or may not be present in the org, and so I have to query non-statically, and catch anyQueryException
caused by the field not being present. Not ideal, but it seems to work.