function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ChrisysChrisys 

Post Chatter Attachment in JSON

Hi,

 

Is there a way or an example chatter post with attachment in JSON using base64 encoding?

 

Thank you!

spatelcespatelce

I'm guessing that you want to generate JSON output on Visualforce page with attachment.

 

If so, may be this can help you.

 

Controller:

public String DispResult { get; set; }

String soql = 'SELECT Id, (SELECT Id, CommentBody, CreatedDate, CreatedById, CreatedBy.FirstName, CreatedBy.LastName FROM FeedComments ORDER BY CreatedDate DESC) FROM FeedItem ORDER BY CreatedDate DESC';

List<FeedItem> myoutput = Database.Query(soql); DispResult = JSON.serializePretty(myoutput);

 

Page:

<apex:page standardController="FeedItem" extensions="extentionname" cache="true" contentType="application/json">
    {!DispResult}
</apex:page>

 

 

Hope this will help.

 

-Saw