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
MattreyMattrey 

No InsertedById on FeedComment

I've got a trigger that runs on FeedComment and I need the id of the user inserting it so according to the documentation I should be able to get this via feedComment.InsertedById but debug shows this as null and if I debug the feed comment I get something like: FeedComment:{ParentId=0055000000XXXXXXXX, CommentBody=my comment body, IsDeleted=false, FeedItemId=0D5R000000XXXXXXXX}

 

Why don't I see an InsertedById?

MattreyMattrey

I just tried it on FeedItem and get the same result for that - no InsertedById

cloudcodercloudcoder

InsertedById will only be used when a post is being inserted on behalf of another user. see the following thread for a discussion:

http://boards.developerforce.com/t5/Chatter-Development/Post-as-a-different-user/td-p/287611

 

 

 

MattreyMattrey

Thanks. So in my trigger, I have use InsertedById unless it's null and if so, use UserInfo.getUserId() ?

cloudcodercloudcoder

depends on what your trigger is doing. You may just want to use CreatedById - which, btw is null in a before insert trigger (I have raised this with the product team).

 

 

MattreyMattrey

I forgot about CreatedById - I was fixating on the documented field list for the FeedItem or FeedComment so I fogot you should always get that.

 

We have a group of users that management does not want to use Chatter, since Chatter is all or nothing, we can't shut it off for that group so I'm trying to write a trigger to show an error message if they try and post or comment. Not an ideal user experience but that's all we've got (as far as I know).

 

I guess it's unlikely that some outside app would try and add posts/comments for these users but as I'm writting a bulk capable trigger, I thought I should probably take it into account.

 

cloudcodercloudcoder

You might want to check out the app I wrote, Chatter Blacklist. You could easily modify that to block users or groups in addition to words and phrases.

 

http://appexchange.salesforce.com/listingDetail?listingId=a0N30000003JqdAEAS

MattreyMattrey

yep - I was using that as the basis for my work. I check for user Ids on a user status update, ParentId on a FeedComment provided it has User prefix (can't have other people trying to Chatter to this group either) and I *was* going to use InsertedById for FeedItem or FeedComment. Do you think it makes sense to still check that and if null, go with UserInfo.GetUserId (as CreatedById doesn't work for trigger before insert)?

 

Thanks