I am creating a Publisher Action that uses a visualforce page and controller. All it essentially does is create an Attachment and insert it, but it works a little bit different from the default 'File' Publisher Action.

After it uploads the Attachment it is supposed to post back to Chatter. When using the default 'File' Publisher Action, you get a nice looking Chatter post with the title of the attachment hyper-linked to the attachment, a 'download file' link, an attachment icon, and a nice box around the whole thing.(See the following)

File Publisher Action Chatter Post

Is there anyway that I utilize this framework, or somehow use this Chatter post format in a FeedItem?

1 Answer 1


Edit - the ConnectAPI can do that - it's not the easiest thing to work with - but if have a regular attachment , this would post that attachment as a Chatter file on an Account's Feed:

Attachment attach = [Select Id, Body, Name, Description, ContentType FROM Attachment    WHERE Id = 'XXX']; //I am querying here - but so long as you have it in a controller, this should work as well.
Account a = new Account(Id = '001XXX'); 

ConnectApi.BinaryInput newChatterFile = new ConnectApi.BinaryInput(attach.Body, attach.ContentType, attach.Name);
ConnectApi.NewFileAttachmentInput cai = new ConnectApi.NewFileAttachmentInput ();
cai.description = attach.Description;
cai.title = attach.name;

    ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
    input.attachment = cai;
    input.visibility = ConnectApi.FeedItemVisibilityType.InternalUsers; 
        //TargetRecordId is the record id of the chatter feed you want to post on
  • I have my attachment stored as an Attachment standard Object. Attachment att = new Attachment(); How do I convert that to a ConnectApi.ContentAttachment? Commented Jan 16, 2014 at 21:04

You must log in to answer this question.

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