I have created a global action that is a visualforce page. I add this to the Global Publisher Layout. Then in chatter I enter some info into the page I built, I format it in my controller and post it to chatter. Everything works as it should, except the feed doesn't update until I manually refresh the page. Does anyone know a way to make an action used in chatter refresh the chatter feed, or whole page?


//called from visualforce page
public PageReference insertIntoFeed() {
   ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput();
   input.subjectId = 'me';
   input.feedElementType = ConnectApi.FeedElementType.FeedItem;
   ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput();
   messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();

   addElement('Field One','line one',messageInput);
   addElement('Field Two','line two',messageInput);

   input.body = messageInput;
   ConnectApi.ChatterFeeds.postFeedElement(null, input);

   return null;

private void addElement(String header, String item,ConnectApi.MessageBodyInput messageInput){
    //add a blank line

private void addListItem(String item,ConnectApi.MessageBodyInput messageInput,Boolean isHeader){
    ConnectApi.MarkupBeginSegmentInput markupBeginSegment = new ConnectApi.MarkupBeginSegmentInput();
    markupBeginSegment.markupType = isHeader? ConnectApi.MarkupType.Bold : ConnectApi.MarkupType.Paragraph;

    ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput();
    textSegment.text = item;

    ConnectApi.MarkupEndSegmentInput markupEndSegment = new ConnectApi.MarkupEndSegmentInput();
    markupEndSegment.markupType = isHeader? ConnectApi.MarkupType.Bold : ConnectApi.MarkupType.Paragraph;
  • Please share your existing code snippet – Gaurav Kheterpal Jul 26 '16 at 8:04
  • @Gaurav Kheterpal Any ideas now? Thanks for taking a look. – visualforceGuy Jul 26 '16 at 18:38

This turns out to be the proper way to accomplish this.

    <apex:commandButton oncomplete="refreshFeed();" action="{!insertintoFeed}" styleClass="btn" value="Submit"  >

 <script type='text/javascript' src='/canvas/sdk/js/publisher.js'/> 
    function refreshFeed() {
            Sfdc.canvas.publisher.publish({name : 'publisher.refresh', payload : {feed:true}});
| improve this answer | |

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.