3

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?

2
  • 1
    Have you tried going through the feed item. FeedComment is a child of FeedItem, which is the child of the record in question. So shouldn't it be FeedComment.FeedItem.Parent.get()?
    – pchittum
    Sep 2, 2013 at 23:42
  • FeedComment.FeedItem gives "Invalid foreign key relationship: FeedComment.FeedItem"
    – George S.
    Sep 3, 2013 at 12:45

1 Answer 1

1

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

FeedItem.Parent.get('Name');

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 any QueryException caused by the field not being present. Not ideal, but it seems to work.

You must log in to answer this question.

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