1

In a lead trigger before update, im trying to post a comment in a chatter group related based upon a field value on my lead. But i'm getting the following error : LeadAfterUpdate: execution of AfterUpdate caused by:

 System.HandledException: Script-thrown exception: (System Code). 

The line that generate this error has this code :

 ConnectApi.ChatterFeeds.postFeedElementBatch(null, batchInputs);

My code is as follows :

  id singleMention = '.....'; //group id  
  set<string> mentionedUsrIdSet = new set<string>();
  id recordId = ''; // id on which to add the post
  String postText = ''; //post body
  List<ConnectApi.BatchInput> batchInputs = new List<ConnectApi.BatchInput>();

  ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();    
  ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
  messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

  ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
  textSegmentInput.text = postText;
  messageBodyInput.messageSegments.add(textSegmentInput);
  ConnectApi.FeedItemInput inputdata = new ConnectApi.FeedItemInput();
  inputdata.subjectId=recordId;
  inputdata.body = messageBodyInput; 
  ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
  mentionSegmentInput.id = singleMention; 
  messageBodyInput.messageSegments.add(mentionSegmentInput);
  ConnectApi.BatchInput batchInput = new ConnectApi.BatchInput(inputdata);
  batchInputs.add(batchInput);

  ConnectApi.ChatterFeeds.postFeedElementBatch(null, batchInputs); 

Does anybody know why and how can i resolve this ? I dont' know if this is related to the new salesforce release or something like this, because the above code where working well with no errors.

2
  • What is the value of batchInputs?
    – Rob
    Commented Sep 17, 2015 at 8:47
  • A list of type ConnectApi.BatchInput. I also tried to modify my api version, but of no use, the problem persist.
    – vanessen
    Commented Sep 17, 2015 at 10:33

1 Answer 1

2

Have you check if the group is public or if the group you are posting is active or archived. There is an option in chatter group, that make a group archived if no post has been created in the group for over 90 days. If this happen, then you can no longer post to that group,without manual activation. Check this out before going into details in the code.

1
  • This is it. The chatter group where archived. I activated it , and tried again. It works fine again. Thanks for help.
    – vanessen
    Commented Sep 29, 2015 at 11:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .