1

I am trying to post to a chatter feed from my Visual Force page. I am using a custom implementation of the chatter feed so I am using an input box and a Command link to try to post to the chatter feed.

Here is the code in my Visual Force page:

<apex:form >
    <apex:inputText value="{!feedItemInputText}"/>
    <apex:commandLink reRender="feedOutputPanel" action="{!postNewFeedItem}" value="Post">           
     </apex:commandLink>
    </apex:form>

And here is the code in my APEX class:

public void postNewFeedItem() {
    // Post to the chatter news feed.
    ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.Record, RecordId, feedItemInputText);
 }

This all works as expected. However on my Visual Force page I have to refresh it to see the newly added post in my Chatter feed. Is there a call back or some way to tell my Visual Force page that the postFeedItem function has completed successfully and that I can now refresh my Visual Force page?

Or is there some other way of achieving this?

1

try it like this, public PageReference postNewFeedItem() { PageReference PageRef=Page.pageyouwanttorefresh; // Post to the chatter news feed. ConnectApi.ChatterFeeds.postFeedItem(null, ConnectApi.FeedType.Record, RecordId,feedItemInputText); PageRef.setRedirect(true); return PageRef; }

| improve this answer | |
  • It works as in it refreshes the page but I also need to send an ID in the URL of the page, I have tried PageReference PageRef=Page.pageyouwanttorefresh+'id'; But the compiler doesn't like it, I guess it may not be possible to send an id to the page this way? – Donal Rafferty Apr 16 '14 at 8:32
  • 1
    true, for sending parameters you need to construct your PageReference like this, PageReference Page=new PageReference('/pageyouwanttorefresh/'+idyouwanttosend). Refer this page for more information,salesforce.com/us/developer/docs/apexcode/Content/… – anmrk Apr 16 '14 at 8:38

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.