+ Start a Discussion
Jacky LeeJacky Lee 

VF page Iframe does not refresh with most up-to-date info after a DML update


I'm trying to figure out why my iframe is not refreshing after a DML update even when explicitly calling a reload function.

I'm displaying an iframe of a chatter:feed component on my visualforce page. Then, I'm grabbing an input text field from the page, passing it to Apex to DML update the chatter:feed component by inserting a comment (I'm doing this instead of just posting a comment within the iframe so I can do some text sanitizing).
function startUpdate(d) {
        var comment = document.getElementById("comment").value;        //get comment input field
        insertComment(comment);        //Insert the comment into the chatter feed through Apex
        document.getElementById("comment").value = '';        //clearing comment field

        refreshIframe();        //Refresh the iframe

After updating the feed element with the comment, I'm trying to refresh the iframe using a javascript function:
function refreshIframe() {
        var iframe = document.getElementById('iframe');
        iframe.contentDocument.location.href = iframe.src;

The issue I'm encountering is that the refreshIframe() function does not fetch the newly inserted comment. There is definitely a 'reloading' animation, but the DML update doesn't appear.
However, when I call the refreshIframe() function from an onclick button, it successfully fetches the feed with the comment:
<button id="saveButton" type="button" class="btn btn-primary" onclick="refreshIframe();">Refresh</button>

I am confused as to why calling the refreshIframe function from within another function does not grab the updated comment, but when invoking from an onclick, it works perfectly fine. In both instances, both functions are called according to the logs.
I am suspecting that onclick does something that I am unaware of, or there is some differences with clearing the cache. Any suggestions are much appreciated.


Hi Jacky,

Mark as best answer, If it resloves !! 
check these similar post

Bhanu Prakash
visit ForceLearn.com