Skip to content

Instantly share code, notes, and snippets.

@lkatney
Last active August 29, 2015 14:14
Show Gist options
  • Save lkatney/a8ac97bdfc8bc13f10e0 to your computer and use it in GitHub Desktop.
Save lkatney/a8ac97bdfc8bc13f10e0 to your computer and use it in GitHub Desktop.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Prior 32.0v
String comment = 'Click to vote/demote this idea';
// Create feed item input
ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
feedItemInput.body = new ConnectApi.MessageBodyInput();
// Create text segment to hold the message body
List<ConnectApi.MessageSegmentInput> segments = new List<ConnectApi.MessageSegmentInput>();
ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
textSegment.text = comment;
segments.add(textSegment);
feedItemInput.body.messageSegments = segments;
// Create the canvas attachment
ConnectApi.CanvasAttachmentInput attachmentInput = new ConnectApi.CanvasAttachmentInput();
attachmentInput.developerName = 'Idea_Vote';
attachmentInput.namespacePrefix = 'lk_main';
attachmentInput.title = 'Vote this idea';
attachmentInput.description = '';
attachmentInput.parameters = '{"id":"087900000008Zli"}';
attachmentInput.height = '100px';
feedItemInput.attachment = attachmentInput;
//Create FeedItemPost//
ConnectApi.FeedItem feedItem = ConnectApi.ChatterFeeds.postFeedItem(null,
ConnectApi.FeedType.RECORD,
'me',
feedItemInput,
null);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//API version 32.0 onwards
ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
input.feedElementType = ConnectApi.FeedElementType.FeedItem;
input.subjectId = 'me';
ConnectApi.TextSegmentInput textInput = new ConnectApi.TextSegmentInput();
textInput.text = 'This is a sample text to support canvas app.';
ConnectApi.MessageSegmentInput messageInput = (ConnectApi.MessageSegmentInput)textInput;
ConnectApi.MessageBodyInput body = new ConnectApi.MessageBodyInput();
body.messageSegments = new List<ConnectApi.MessageSegmentInput>{messageInput};
input.body = body;
ConnectApi.CanvasCapabilityInput canvas = new ConnectApi.CanvasCapabilityInput();
canvas.developerName = 'Idea_Vote';
canvas.namespacePrefix = 'lk_main';//namespace added
canvas.height = '250px';
canvas.parameters = '{"id":"087900000004iGT"}';
canvas.title = 'A new idea has been added with 33.0';
ConnectApi.FeedElementCapabilitiesInput capability = new ConnectApi.FeedElementCapabilitiesInput();
capability.canvas = canvas;
input.capabilities = capability;
List<ConnectApi.BatchInput> feedElements = new List<ConnectApi.BatchInput>();
ConnectApi.BatchInput element = new ConnectApi.BatchInput((object)input);
feedElements.add(element);
ConnectApi.BatchResult[] results = ConnectApi.ChatterFeeds.postFeedElementBatch('internal', feedElements);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment