FeedAttachment
Represents an attachment to a feed item, such as
a file attachment or a link. Use FeedAttachment to add various attachments to one
feed item.
This object is available in API version 36.0 and
later.
Supported Calls
create(), delete(), describeSObjects(), idEnabled(), query(), retrieve(), update(), upsert()
Special Access Rules
- You can read, create, update, or delete a FeedAttachment only if you have the corresponding access to the associated FeedItem.
- Inline images aren’t creatable, updatable, or deletable through SOAP API.
Fields
Usage
- This Apex example shows how to add an attachment to a Lead using API version
36.0 and later. First, post a feed
item.
//create and insert post FeedItem post = new FeedItem(); post.Body = 'HelloThere'; post.ParentId = 'ID_OF_LEAD_ENTITY'; post.Title = 'FileName'; insert post;
Then insert the attachment.//create and associate a content attachment to the post FeedAttachment feedAttachment = new FeedAttachment(); feedAttachment.FeedEntityId = post.Id; feedAttachment.RecordId = 'ID_OF_CONTENT_VERSION'; feedAttachment.Title = 'FileName'; feedAttachment.Type = 'CONTENT'; insert feedAttachment;
- You can create only one link attachment (FeedAttachment of type Link) per feed item.
- If the feed item type is one of the following, you can add content or link feed
attachments to a FeedItem.
- AdvancedTextPost
- TextPost
- ContentPost
- LinkPost
- QuestionPost
- When a FeedAttachment is added or removed from a feed item,
Salesforce updates the type of the feed item to its most appropriate value, as follows.
- If all content feed attachments are removed from a feed item of type ContentPost, the type of this feed item is updated to TextPost.
- Conversely, if a content feed attachment is added to a feed item of type TextPost, the type of this feed item is updated to ContentPost.
- If all link feed attachments are removed from a feed item of type LinkPost, the type of this feed item is updated to TextPost.
- Conversely, if a link feed attachment is added to a feed item of type TextPost, the type of this feed item is updated to LinkPost.
- The type of all other feed items, such as QuestionPost or AdvancedTextPost feed items, doesn’t change when any feed attachments are added or removed.
- If a content feed attachment is added to a feed item of type LinkPost, the feed item type is updated to ContentPost.
- If all content attachments are removed from a feed item of type ContentPost, but there's also a link attachment, the feed item type is updated to LinkPost.
- Users without administrator privileges can’t retrieve a FeedAttachment by its ID
in a SOQL query. They can retrieve attachments by specifying the associated
FeedEntityId, as
follows:
SELECT Id FROM FeedAttachment WHERE FeedEntityId = 'some_feedItem_id'
- Alternatively, retrieve attachments by using a SOQL query on FeedItem with a
subquery on the FeedAttachments child relationship, as
follows.
SELECT Body, (SELECT RecordId, Title, Type, Value FROM FeedAttachments) FROM FeedItem WHERE Id = 'some_feedItem_id'
- FeedAttachment is not a triggerable object. You can access feed attachments in FeedItem update triggers by retrieving them through a SOQL query. For a trigger example, and to learn about trigger considerations for FeedAttachment, see Triggers for Chatter Objects in the Apex Developer Guide.