I'm trying to send the message to the users in my organisation on chatter from Apex class. Sample user hierarchy where I'm trying to send the message is given below:

User 1
    |----user 2
              |----user 3
              |----user 4
                          |----user 5
                          |----user 6

Message sending is working fine when I am sending message from higher hierarchy user to lower hierarchy user. But from a user who is lower in hierarchy to a user who is higher in hieerachy, it is not working correctly. eg. If i want to send message from user 1 to any user . It is working correctly. but If I want to send from user 6 ---- > to user 5 , User 4 -----> to user 3 ,2, 1. It is throwing below error.

Error occured...Insufficient Privileges: You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.....Class.ConnectApi.ChatterFeeds.postFeedElement: line 4277, column 1

Code to send the chatter message is given at the end. I'll appreciate if you can suggest any solution to the issue. i.e

1- If I can send message from user who is lower in hierarchy to a user who is higher in hierarchy. 2- If I can't send message to user who is higher in hierarchy, then what are the altearnatives available.

// makes a simple chatter text post to the specified user from the running user 
///comnrtrller class method to send message
public static void simpleTextPost(Id userId, String postText)
     ConnectApi.FeedType feedType = ConnectApi.FeedType.UserProfile;    
      ConnectApi.MessageBodyInput messageInput = new     ConnectApi.MessageBodyInput();
        messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
                // add the text segment        ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
        textSegment.text = postText;
        ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
        feedItemInput.body = messageInput;        
        // post it
        ConnectApi.ChatterFeeds.postFeedElement(null, userId,            ConnectApi.FeedElementType.FeedItem, postText);
        //ConnectApi.ChatterFeeds.postFeedItem(null, feedType, userId, feedItemInput, null);  

 } //simpleTextPost    

///method call from apex controller class
simpleTextPost(User 1.id , myMessage);

Thanks in advance for your valuable time and help :)


Chetan Kamble

  • Is your OWD set to private ? – MIX DML Jul 11 '16 at 7:46
  • Thanks Prabhat Kumar, I changed owd private to public/read write and it solved my issue. – Vicky Jul 12 '16 at 8:56
  • Glad to know it worked for you. You can select the solution as answer so that other people can get benefit from the question. – MIX DML Jul 12 '16 at 10:23

It is happening because your OWD setting is set to Private. Change it to public/read write and check if it works.

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.