You need to sign in to do that
Don't have an account?

Post as a different user
Trying to insert a Chatter Feed record as a User which is not the executing user
FeedItem fi = new FeedItem(Body = 'Hello World', ParentId = '<ID OF USER>');
insert fi;
But this inserts it as a FeedItem from the executing User to the User whose Id is plugged into the FeedItem.
FeedItems seem to be created in the executing Users Chatter Stream.Wondering what I'm missing.
You need to make sure the user you are using to the insert the post has the "Insert System Field values for Chatter" attribute enabled on their profile. From the Winter 11 release notes:
"This field is the ID of the user who added this object to the feed. For example, if a client application migrates multiple
posts and comments from another application into a feed, then InsertedById is set to the ID of the logged-in user.
If the logged-in user has the Insert System Field Values for Chatter Feeds user permission, the create field property is available on CreatedById and CreatedDate system fields for this object. This allows the logged-in user to set these fields to the original post author and creation date upon migration instead of accepting the system field value when migrated, which would be the logged-in user and the date the migration was performed, respectively. The fields can't be updated after migration."
Once you have that attribute enabled, you can set the CreatedById field, with the actual inserting users id being recorded in InsertedById.
The following code snippet will insert as the user as identified by other-user-id:
All Answers
You need to make sure the user you are using to the insert the post has the "Insert System Field values for Chatter" attribute enabled on their profile. From the Winter 11 release notes:
"This field is the ID of the user who added this object to the feed. For example, if a client application migrates multiple
posts and comments from another application into a feed, then InsertedById is set to the ID of the logged-in user.
If the logged-in user has the Insert System Field Values for Chatter Feeds user permission, the create field property is available on CreatedById and CreatedDate system fields for this object. This allows the logged-in user to set these fields to the original post author and creation date upon migration instead of accepting the system field value when migrated, which would be the logged-in user and the date the migration was performed, respectively. The fields can't be updated after migration."
Once you have that attribute enabled, you can set the CreatedById field, with the actual inserting users id being recorded in InsertedById.
The following code snippet will insert as the user as identified by other-user-id:
I wouldn't have figured that one ! Thanks Quinton :)