In my org ConnectApi.FeedItem used in many places so I think we can have general class to make it work from different logics to avoid duplicate code.
so for that i created a class and implement that logics but for single post its working fine but when i used in a batch class its not working so can any one suggest me how do we do that :
here is my code:
public class WrapperConnectApi {
public static void feedItem(String subId,String mentionId,String msge){
List<ConnectApi.BatchInput> inputs=new List<ConnectApi.BatchInput>();
ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.subjectId = subId;
ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
mentionSegmentInput.id =mentionId; // chatterGroup.Id;
ConnectApi.MessageBodyInput body = new ConnectApi.MessageBodyInput();
body.messageSegments = new List<ConnectApi.MessageSegmentInput>();
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text =' '+ msge;
body.messageSegments.add(mentionSegmentInput);
body.messageSegments.add(textSegment);
input.body = body;
ConnectApi.BatchInput batchInput = new ConnectApi.BatchInput(input);
inputs.add(batchInput);
if(inputs.size() > 0)
ConnectApi.ChatterFeeds.postFeedElementBatch(Network.getNetworkId(), inputs);
}
}