Creates a new FeedItem record, which appears as a post in the chosen record's Chatter feed. One or more file attachments can be added to this item with createFeedAttachment commands.

Content of the post

The body content of the created Chatter post may be just plain text, but it can also be considerably more complex content featuring rich text formatting, images, links, mentions and topics. These features can be defined mainly through HTML-like tags appearing within the content. Here's an example:

Something <i>strange</i> is going on.  <p>Could @[${userID}] take a look?</p> #dynamoMysteries

This would appear in the Chatter feed as something like this:

The content can be defined in a couple ways. The body attribute can be resolved into either a String or a File with the content. Alternatively, one can place the content into CDATA under this command. Regardless of the way used, the resulting content String is then parsed into the proper Chatter message structure. Any errors in the structure can cause Salesforce to reject the creation of the post, so one should be careful when crafting messages of the more elaborate kind.

Content syntax

Rich text formatting and images can be added through the tags described below. Note that all tags have to be closed, unlike the HTML tags these resemble, so for example a <p> must have a matching </p> later on in the content. Any other tags have no effect.

Tag Description
a A link. This tag requires an attribute, href, whose value needs to be an URL to which the link links to. Any text within the tag is displayed as the link. 
b Text within the tag is bolded.
i Text within the tag is italicized.
img An inline image. This tag requires an attribute, src, whose value needs to be the ID of an image ContentDocument record within the organization, eg. <img src="${imageRecordID}"></img>
li Creates a list item with the content within the tag. Use within <ol> or <ul>.
ol Creates an ordered list. Any list items within, created with <li> tags, are numbered starting from 1.
p Creates a paragraph. Each paragraph starts on a new line, so this tag is a way to generate line breaks.
s Text within the tag is struck-through.
u Text within the tag is underlined.
ul Creates an unordered list. Any list items within, created with <li> tags, receive ordinary bullets.

Mentions and entity (record) links can be defined with a mostly shared syntax. To add a mention, place @[targetID] into the content, with the "targetID" being the ID or a User or Group within the organization. This is typically resolved through EL, so mentions tend to look like @[${targetID}] in the content. To add a link to some other kind of record, place [recordID] into the content, with the "recordID" being the ID of the record you wish to link to.

Hash tags (topics) can be added by placing  #topic into the content, with the "topic" being a topic to tag the post with.

In addition to using the <a> tag, Links can be added into the post by simply placing the link address into the content and making sure it has a space before and after it. It then turns into a functional link in the post, but do note that the link text in this case is always the address itself.

Child commands

  • createFeedAttachment
    Optional. Add one of these child commands for every file attachment you wish to add to the post and leave their feedItemID attribute undefined.

Attributes

var

Required
Value type
EL-evaluated
No String No
If defined, a variable with this name is created to hold the ID of the created FeedItem record. 
parentId

Required
Value type
EL-evaluated
Yes String Yes
Defines the record whose Chatter feed receives the new post. The resolved String should be the ID of the record.
body

Required
Value type
EL-evaluated
No String, File Yes
Defines the text content of the message. The content may contain formatting syntax as described in this command's main documentation.

If not defined, the message's content will be "-" as Salesforce rejects posts that do not have a body of at least one non-space character. 
title

Required
Value type
EL-evaluated
No String Yes
Defines the title of the created feed item.

Examples

A common reason for a Flow to use this command is to post a composed document into a Chatter feed. The command can't do this alone, though. The createFeedAttachment command needs to accompany postFeedItem for the document to be attached into the post. Also, as a feed post's attachment has to be a file in Salesforce (specifically a ContentVersion/ContentDocument record, not an Attachment or such), the composed document needs to be uploaded into Salesforce with createContentVersion. So, to post your document into Chatter, the following can do the job:

<composeContent var="composedDoc" value="Document/content.html">
<postFeedItem parentId="${mainRecordID}">
  <createFeedAttachment>
    <createContentVersion doc="${composedDoc}">  

Instead of placing createContentVersion as the child of createFeedAttachment, the attached file can be defined with createFeedAttachment's contentRecordID attribute. This comes useful if you wish to upload your document into Salesforce earlier in the Flow, or if you want to attach a file already existing in Salesforce - or do both. Maybe something like this:

<composeContent var="composedDoc" value="Document/content.html">
<createContentVersion var="saveResult" doc="${composedDoc}">  
... 
<postFeedItem parentId="${mainRecordID}">
  <createFeedAttachment contentRecordID="${saveResult.contentVersionId}">
  <createFeedAttachment contentRecordID="${anotherDocumentID}">

You can also just attach files to an already existing Chatter post instead of a newly created post. In this case, use the feedItemID attribute of createFeedAttachment to specify the target post:

<createFeedAttachment feedItemID="${targetPostID}" contentRecordID="${saveResult.contentVersionId}">
<createFeedAttachment feedItemID="${targetPostID}" contentRecordID="${anotherDocumentID}">