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.
batchInputs
?