[SalesForce] Is it possible to post a url to an Opportunity in a simple chatter post

I'm trying to make a chatter post that includes the Opportunity name as a URL. So basically it will be something like: TestOpportunity which would take the user to the actual Opportunity when they click on it. Right now I have it posting as text. Is this possible in a simple chatter post? Thanks in advance for the help!

Update: I managed to get the URL using:

String URL = URL.getSalesforceBaseUrl().toExternalForm() + '/' + opp.Id;

How can I put the Opportunity Name as the URL instead of the ugly URL? Possible?

FeedItem post = new FeedItem();
post.ParentId = oppOwnerId.Id;
post.createdById= oppOwnerId.Id;
post.Body = 'Opportunity ' + opp.Id; 
insert post;

Best Answer

is something like this sufficient? The Op Name is a clickable link, though the Id is visible in the post as well.

Opportunity o = [Select OwnerId, Id, Name from Opportunity WHERE Id = 'xxx'];

FeedItem post = new FeedItem();
post.ParentId = o.OwnerId;
post.createdById= o.OwnerId;
post.Type = 'LinkPost'; 
post.Title = o.Name;
post.LinkURL = '/'+ o.Id;
insert post;

Or do you need more of the rich text mentioned in the post you link to (which is possible via ConnectAPI if you need an example - let me know)

Related Topic