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
Carolina W 2Carolina W 2 

How can I change the FeedItem's sender?

Hi!
In the case of the image, the user Alanna Clark updated an account and my trigger runned and posted the FeedItem.

But I want to change the sender ("Alanna Clark")  for another the user called "INTERFACE" when the trigger runs. What do I have to do? 

//Feed Post
FeedItem post = new FeedItem();
post.Body = 'Msg body';
post.ParentId = acc.Id ;
insert post;
 

User-added image

Vishwajeet kumarVishwajeet kumar
Hello,
You need to run 'Feed Item' insertion code as "Interface" user, it needs to be moved out of trigger.

Try Somthing like this : 
You can mark some checkbox or field data which can identify that you need to insert Feed Item for particular record in trigger and then 'Feed Item' insertion can be done using Scheduled Job (Run as "Interface" user, Async process). 

Thanks
Malika Pathak 9Malika Pathak 9
Hi Carolina,

Try this:
You can set the user that posted the message by adding the userId here
FeedItem post = new FeedItem();
post.CreatedById = '0053000000AD9YT';
post.Body = 'Msg body';
post.ParentId = acc.Id ;
insert post;
If you found this answer helpful, please mark it as the best answer to help others.