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
LouShropshireLouShropshire 

Chatter FeedItem Style/ Type in Apex

How do I create a Chatter Post that looks like this?

 


What I want to do is, have a trigger that calls a function to create a chatter post when a new contact is created. I want it to look like the image below. Right now, I have a trigger on 'Contact' that calls a function, but I'm not sure of how to create a Chatter FeedItem that looks like this.

 

Sample Chatter Post


Is there a certain FeedItem Type that will do this?
Or is there a way for me to add style to the FeedItem?

Best Answer chosen by Admin (Salesforce Developers) 
alouie_sfdcalouie_sfdc

These types of feed items are automatically created when you use Publisher Actions to "quick create" a record.

 

You can use the QuickAction namespace in Apex to create records, which will automatically generate a feed item like the one in your screenshot. Here are the docs:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_namespace_QuickAction.htm

 

The SOAP API also lets you use quick actions to create records:

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_performquickactions.htm

 

In your example, if you create a new contact through the normal way on the Contacts tab, you won't be able to write a trigger that produces a feed item like the one you want. Those feed items are system-generated. You'd have to create a "New Contact" publisher action and use either the Publisher UI or the API to create the contact, which would generate the feed item.