We have our Salesforce instance configured so that when a Task is created, this is posted to the Chatter feed:
When I query for the feeditem created for that task creation event:
SELECT
Id, Body, InsertedById, IsRichText, LinkUrl, NetworkScope, ParentId,
RelatedRecordId, Status, Title, Type, Visibility
FROM FeedItem
WHERE ParentId = 'MY_TASK_ID_HERE'
I can see the FeedItem
with a Type
= CreateRecordEvent
, and a null Body
, LinkUrl
, and RelatedRecordId
.
When I try to create something like this programmatically with Apex:
FeedItem item = new FeedItem(
Type = 'CreateRecordEvent',
createdById = 'MyUserId',
ParentId = 'MY_TASK_ID_HERE',
Visibility = 'AllUsers'
);
insert item;
The insert succeeds with no errors. I am able to then
SELECT Id, ... Visibility FROM FeedItem WHERE Id = 'INSERTED_FEEDITEM_ID'
And the new FeedItem is returned. However no chatter post is visible on the Account's chatter feed.
Why isn't this new FeedItem appearing on the Account's chatter feed?
Note the docs are either inconsistent or misleading, because for the Type
field, they show a "CreatedRecordEvent" Type
- note the Created with a d, vs the type created automatically is a type of CreateRecordEvent.
If this is impossible, which it seems to be, how could I mimic the "created a record" Chatter post to link to a record ID so that it opens in a subtab and follows the same behavior as a record link?
When I try to make a Type = "LinkPost"
and set LinkUrl = URL.getSalesforceBaseUrl().toExternalForm() + '/' + MY_TASK_ID
, or do the same thing with a post body and an <a>
tag, the link opens in a new tab.