• Chetan Kamble
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
Dear Friends,

Greetings!

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.

Thanks in advance for your valuable time and help :)

Regards

Chetan Kamble

// 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;
        messageInput.messageSegments.add(textSegment);        
        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);
How can i validate mobile number should be 10 digit in trigger.I have created a trigger but its not working
trigger MobileNumber on Account (before update,before insert) {
 if( Trigger.isbefore && Trigger.isInsert)
    {
    for(Account l: Trigger.New){
        if(l.Mobile__c!=null && Mobile__c.lenght()=10){
alert ("Error");
        
    
      
        }
    }
}



}

 
Dear Friends,

Greetings!

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.

Thanks in advance for your valuable time and help :)

Regards

Chetan Kamble

// 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;
        messageInput.messageSegments.add(textSegment);        
        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);