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
Mike JackMike Jack 

Window Reload from Chatter

Hi All,

I have created a Global Action and Published in the Chatter Layout. The Action Type of Global Action is Custom Visualforce. The VisualForce page consists of a button when clicked it perform an action to Post some text to the Chatter.
I can able to Post to the Chatter successfully but I have to reload the Window to see my Post. But the window should be automatically reloaded once the button is clicked to show the inserted Post.

Here is the Screenshot of the Chatter with Global Action which consists the VF Page:
User-added image
Here is the VF Page:
<apex:page controller="PracticeClass" >
    <script>
    function refreshPage(){ 
        
        window.location.reload();
    }
    </script>
    
    <apex:form >
        <div align="center" style="margin:100px auto" >
            <apex:inputTextarea  />
            <apex:commandButton value="PostToChatter" action="{!PostToChatter}" onclick="refreshPage()" />            
        </div>
    </apex:form>
</apex:page>

Here is the Controller:
public class PracticeClass {
    
    public void PostToChatter()
    {
        FeedItem post=new FeedItem();
        post.Body= 'Your Feed is Posted 12345';
        post.ParentId= '00528000001KZre';
        insert post;
    }
}

Thanks in Advance,
Mike J
Andrew LokotoshAndrew Lokotosh
Hello Mike!
Looks like you need to use Asynchronous JavaScript for whis work. But that is not possible when you use VF page on Page Layout. 
You need to find another way to solve that task. For example create custom VF page on new window and use Chater API to load all posts, and go forward to rerender that aria.

Please mark that as best answer if that helped you.

Best regards
Andrew
Mike JackMike Jack
Hi Andrew,
Appreciate your response.

If its not so much to ask, can you share few references on using Chatter API to load posts in VF page.

Thanks in Advance,
Mike J
Jared HagemannJared Hagemann
So I ran into a very similar issue while developing a custom global action.  After the custom global action completed I needed to refresh the page, and since the global action is inside an iframe i needed to refresh the parent window.  I did a lot of searching and normally you would be able to simple use:
window.parent.location.refresh()

I found that the window.parent.location value is actually blank inside the iframe, so i had to rebuild the the url for the parent page, i did this by passing in the Id of the record (in my case a chatter group id) as a url parameter and used the following javascript:
function reload(){
		//get ID paramater from URL
		var query = window.location.search.substring(1);
		var pair = query.split("=");

		//get url of page inside iframe
		var url = window.location.href;

		//get base url
		url = url.substring(0, url.length - 48);

		//add parameter to end of url
		url += pair[1];

		//refresh parent with url
		window.parent.location = url;
	}
	window.onload = reload();

I wanted to post this incase someone else ran into the same issue.