4

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;
1

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)

2
  • This is perfect. Exactly what I wanted. Thank you so much! – user988 Nov 29 '13 at 20:00
  • Note this is not a proper salesforce link to the record, it will always open in a new tab – Andy Ray Feb 25 '20 at 7:20
0

Looks like this same question was asked here. Not the answer you are looking for unfortunately.

1
  • yeah I saw that one. But not the answer I was looking for you're right. Thanks – user988 Nov 26 '13 at 19:17
0

Or you can use the ConnectAPI - which would look something like this:

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

ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
ConnectApi.LinkAttachmentInput linkAttach = new ConnectApi.LinkAttachmentInput();

linkAttach.URL =  URL.getSalesforceBaseUrl().toExternalForm() + '/' + o.Id;
linkAttach.URLName = o.Name;

input.attachment = linkAttach;

ConnectApi.FeedItem feedItemRep = ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.UserProfile, o.OwnerId, input, null);

The link is still visible in the post, but the name is now a clickable link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.