2

Urgent Help Needed:

I am getting exception while updating a chatter feed using ConnectApi.ChatterFeeds class.

I am not getting it regularly but for some specific users under a particular custom profile i am seeing this error.

Need help in figuring out what is the field in the profile or org level that is controlling this.

 

trigger FeedItemBodyModify on FeedItem (after insert) {

    List fiIds = new List(); 
    for(FeedItem fi : Trigger.new)
    {
        if('Position__c' == String.valueOf(fi.ParentId.getSObjectType())){
            fiIds.add(fi.Id);
        }

    }

    if(null != fiIds && fiIds.size() > 0){
        String commID = Network.getNetworkId();
        ConnectApi.BatchResult[] feeds = ConnectApi.ChatterFeeds.getFeedElementBatch(commID, fiIds);

        for (ConnectApi.BatchResult result : feeds) {
            if (result.isSuccess()) {
                Object theResult = result.getResult();
                if (theResult instanceof ConnectApi.FeedItem) {
                    ConnectApi.FeedItem item = (ConnectApi.FeedItem) theResult;   
                    ConnectApi.FeedItemInput input = ConnectApiHelper.createFeedItemInputFromBody(item.body);

                    ConnectApi.TextSegmentInput textInput = new ConnectApi.TextSegmentInput();
                    textInput.text = 'Disclaimer: Modified in a trigger.';

                    ConnectApi.TextSegmentInput lineTextInput = new ConnectApi.TextSegmentInput();
                    lineTextInput.text = '---';

                    ConnectApi.TextSegmentInput blankTextInput = new ConnectApi.TextSegmentInput();
                    blankTextInput.text = ' ';

                    ConnectApi.MarkupBeginSegmentInput markupBeginInput = new ConnectApi.MarkupBeginSegmentInput();
                    markupBeginInput.markupType = ConnectApi.MarkupType.Paragraph;

                    ConnectApi.MarkupEndSegmentInput markupEndInput = new ConnectApi.MarkupEndSegmentInput();
                    markupEndInput.markupType = ConnectApi.MarkupType.Paragraph;


                    input.body.messageSegments.add(markupBeginInput);
                    input.body.messageSegments.add(blankTextInput);                     
                    input.body.messageSegments.add(markupEndInput);
                    input.body.messageSegments.add(markupBeginInput);
                    input.body.messageSegments.add(lineTextInput);                     
                    input.body.messageSegments.add(markupEndInput);
                    input.body.messageSegments.add(textInput);

                    System.debug(input.body.messageSegments);

                    ConnectApi.ChatterFeeds.updateFeedElement(commID, item.id, input);
                }
            }
        }
    }

}

 

enter image description here

1

It's the "Edit my own posts" profile setting.

From the blog post:

In order for this to work, the “Allow users to edit posts and comments” Chatter setting must be on, and the “Edit my own posts” user profile permission must be enabled for all users who post to Chatter. This is very important. Any users who don’t have permission to edit their own posts will see errors when they attempt to post.

For more info, see the release notes.

Edit :
if 'Moderate Chatter' is enabled, by default user gets privilege to edit a chatter post. So either 'Moderate Chatter' or 'Edit my own posts' must be checked for the profile in order to update chatter feed from trigger.

  • But there are other user who does not have that check enable, and code is working fine with them. They don't have any permission set as well. – Saumya Ranjan Satapathy Mar 4 '16 at 8:25
  • It seems if 'Moderate Chatter' is checked then 'Edit my own posts' is not required. I mean it overrides.So if 'Moderate Chatter' or 'Edit my own posts' is checked, the code will work fine. Thanks for your quick response. – Saumya Ranjan Satapathy Mar 4 '16 at 9:08

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.