3

I have a trigger that posts to a Project Object's feed and @mentions someone. The only problem is that I need to be able to post the message as another user, not the user who is logged in. How can I do this? Here is my trigger.

trigger autoProjectChatter on Milestone1_Project__c ( after update) {
  for(Milestone1_Project__c project : Trigger.New) {
    if (project.Project_stage__c == 'Ready to Deliver') {

        string what = project.Id;
        string name = 'Album';

        String communityId = null;
        ConnectApi.FeedType feedType = ConnectApi.FeedType.Record;

        ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
        ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
        ConnectApi.TextSegmentInput textSegment;
        ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput();

        messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

        mentionSegment.id = '005j0000000Y3tO';
        messageInput.messageSegments.add(mentionSegment);

        textSegment = new ConnectApi.TextSegmentInput();
        textSegment.text = ' Brenda, I am pleased to announce that we have completed the project under budget, and well within our proposed timeline!';
        messageInput.messageSegments.add(textSegment);

        input.body = messageInput;
        //input.subjectId = t.whatID;


        ConnectApi.FeedItem feedItemRep = ConnectApi.ChatterFeeds.postFeedItem(communityId, feedType, what, input, null);







       }  
     }
    }
5

Unfortunately the ConnectApi classes currently don't support posting as another user. See here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_differences.htm

The FeedItem SObject API supports impersonation, but it doesn't support posting @-mentions. So it's currently not possible to make an @-mention as another user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.