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
gil_garciagil_garcia 

Linking objects in chatter feed

I want to make a chatter post but link a salesforce object to it. I am new to salesforce development and really new to chatter development so if anyone could help me out that would be great thanks

Best Answer chosen by Admin (Salesforce Developers) 
spatelcespatelce

I must admit that this is impressive and real life example which helps in picturize question. So, here is a sample code that should work in same fashion you want it to be:

 

This is a trigger that you will have to write on your custom object and it will make a chatter post on chatter wall.

 

trigger My_Marker on Marker__c (after insert) {

String status;
FeedItem post = new FeedItem();

for(Marker__c m : Trigger.new) {
if(Trigger.isInsert) { status = 'Wow I really like ' + m.Name + '. My favorite is ' + m.color__c + ' with ' + m.pointer_type__c + ' tip.'; post.ParentId = '15-digit Id, where you want to see post'; post.Title = m.Name; post.Body = status; }
} insert post; }

 

Hope this will help you.

 

-Saw

All Answers

spatelcespatelce

Hi,

 

If I understood correctly then you want to have chatter post that have "hyperlink text" to Salesforce object. Would you please elaborate more on this?

gil_garciagil_garcia

lets say i want to code auto chatter posts and i want to include custom fields from custom objects i have made within salesforce

 

example:

I have a custom object "marker" with fields such as "name", "color", and "point type" and i want a chatter post to be made automatically about this marker is there a way to be lik "wow I really like "marker.name". My favorite is "marker.color" with 'marker.pointer_type" tip." 

 

sorry thats a really bad example but i had a marker sitting next me and its as simple as i could get while explaining what i wanted to do.

spatelcespatelce

I must admit that this is impressive and real life example which helps in picturize question. So, here is a sample code that should work in same fashion you want it to be:

 

This is a trigger that you will have to write on your custom object and it will make a chatter post on chatter wall.

 

trigger My_Marker on Marker__c (after insert) {

String status;
FeedItem post = new FeedItem();

for(Marker__c m : Trigger.new) {
if(Trigger.isInsert) { status = 'Wow I really like ' + m.Name + '. My favorite is ' + m.color__c + ' with ' + m.pointer_type__c + ' tip.'; post.ParentId = '15-digit Id, where you want to see post'; post.Title = m.Name; post.Body = status; }
} insert post; }

 

Hope this will help you.

 

-Saw

This was selected as the best answer