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
WYamWYam 

Chatter Post.add()

Hey everyone! Starting to work a little bit using triggers in Salesforce relative to Chatter.

 

Business Case:

We are trying to update the chatter feed of the Opportunity when a change to a specific field is made. Ideally, we'd like to post the following in the chatter post details.

 

<OpportunityLineItem Link> -- <Account Link>

 

 

Here is the snippet of code that we're working with now:

 

            if(opportunityFeedPosts.size() == 0 || opportunityFeedPosts[0].FeedPost.Body != bodyText) {
//System.debug('OpportunityFeed Posts: '+opportunityFeedPosts[0]);

FeedPost opportunityPost = new FeedPost ();
opportunityPost.Type = 'LinkPost';
opportunityPost.Title = ''+entries.get(newOLI.Pricebookentryid).Product2.ProductCode+' socket details';
opportunityPost.Body = bodyText;
String id = String.valueOf(newOLI.Id).substring(0,15);
opportunityPost.LinkURL = 'https://cs2.salesforce.com/'+id;
opportunityPost.ParentID = newOLI.opportunityid;
posts.add(opportunityPost);
System.Debug('Got Here but did not post');

FeedPost opportunityPost2 = new FeedPost ();
opportunityPost2.Type = 'LinkPost';
opportunityPost2.Title = 'Account Details';
opportunityPost2.Body = bodyText;
String id2 = String.valueOf(opp.get(newOLI.OpportunityId).Account.Id).substring(0,15);
opportunityPost2.LinkURL = 'https://cs2.salesforce.com/'+id2;
system.debug('got here and it should have posted twice');
opportunityPost2.ParentID = newOLI.opportunityid;
posts.add(opportunityPost2);

 

 

The Result:

 

We get two posts where the message title is the same but the post bodies are different. Essentially we get a double post with each having a unique link for one to the opportunitylineitem and the other to the account.

 

Any help or quesitons are greatly appreciated!

 

 

rwoollenrwoollen

Sorry we should give clearer validation here.

 

For LinkPosts, you just want to use Body and LinkURL.  THe Body is what is displayed in the UI just above the link.  Title is unused

WYamWYam

Are you sure about that? I tried to figure out where each item was going and yes the Body is the the text immediately after the user detail... However, the Title is currently what gets hyperlinked in the UI; the text on which the URL lives.

 

As it appears on the screen:

 

X person <Body>

<Title w/Link>

 

We could solve the issue by putting a link in the body or adding a second Title with a link but that seems less feasible.

 

 

rwoollenrwoollen

Sorry on closer inspection, you're correct.  The Body is used right after user, the TItle is used as the link text.

d3developerd3developer

I think putting it in the body is your best option.