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
EEEEEE 

Refresh Home Page and/or Dashboard

I had some success today refreshing dashboard and thought I'd share. I found some code from SF Heretic on refreshing homepages and dashboards, but it didn't quite work for me, though it got me pointed in the right direction which I greatly appreciate! Their code for refreshing the homepage didn't work for me the way it was setup. What did work was going to Homepage components and adding to the Messages & Alerts:

<meta http-equiv=refresh content=600>

And if you stay on the home page it does refresh after 10 minutes.

What I wanted to do was refresh a dashboard we have for mgmt users whenever they hit that page so they see the current numbers without having to click refresh. What I ended up doing was adding a component to the dashboard that was an S Control and all it contained was the following code where the ID listed is the ID of the dashboard. You can see the exact window open code I lifted below by going to the dashboard and with FIREBUG installed click INSPECT and select the REFRESH button on the page and it will show you something like the below....

Code:
<BODY onLoad="refreshDashboardTimeout();" >
<script>
function refreshDashboardTimeout() {
window.open('/01Z6000000073av—m=poll&refresh=1', 'db_refresh_frame');
}
</script>

Hope that helps some of you out there..........

E





Best Answer chosen by Admin (Salesforce Developers) 
EEEEEE
Right. You create an S-Control that is HTML. This is my latest version, though I have a couple versions of this where I use this concept to make SF wake up and do something for me (rotate leads outside of protection perido to queue ownership for example). For just the dashboard refresh use this:
 
Code:
<head>
<title>Dashboard Refresh</title>
<link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet">
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/dJS/en/1176317276000/library.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/031907/desktop/desktopAjax.js"></script>
<script type="text/javascript" src="/static/031907/js/functions.js"></script>
</head>

<BODY onLoad="bodyOnLoad();" >

<script type="text/javascript">
function bodyOnLoad() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '—m=poll&refresh=1', 'db_refresh_frame');
int = self.setInterval("refreshnow()",600000);
//int = self.setInterval("refreshnow()",100000);
}

function refreshnow() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '–m=poll&refresh=1', 'db_refresh_frame');
}
</script>

 Once you create the S-Control go to your dashboard and create a new component that is S-Control. I put no header, footer, and make the height 1, then stick that component at the bottom of the dashboard (it shows up as a line). In the S-Control it finds the ID of the dashboard using the URL and pageID variables, then the INT sets a variable to call the refreshnow function every X number of seconds. 600000 is about 10 minutes, turn it down to 100000 for testing and that refreshes every 5 minutes or so.
 
The only problem I have had with this code is if a user takes the dashboard and adds it to their homepage it won't refresh properly b/c the ID of the page is the homepage not the dashboard. If you want that to work hardcode the ID of the dashboard into the S-Control so it doesn't rely on the URL and pageID to know what to refresh.

All Answers

EEEEEE
Just thinking this could be automated further by finding the URL of the dashboard you're on and grabbing the ID from there so the same scontrol could be embedded in many dashboards without having to be customized for the particular dashboard ID........
EEEEEE
This code finds the ID of the dashboard and refreshes it. You can use this in any dashboard by embedding an scontrol with this code. I like that better....

Code:
<BODY onLoad="refreshDashboardTimeout();" >

<script>
function refreshDashboardTimeout() {

var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'))
window.open(pageid + '—m=poll&refresh=1', 'db_refresh_frame');
}
</script>

 

chopairchopair
I am new to development so I would like to confirm, are you saying that if I create an s-control that contains this code and place it on any of my dashboards, that when the dashboard is selected, it will automatically be refreshed without having to select the refresh button?

Do you know if there is a way to have this refresh scheduled say every 30 or 60 mins using a scripting tool?
EEEEEE
Right. You create an S-Control that is HTML. This is my latest version, though I have a couple versions of this where I use this concept to make SF wake up and do something for me (rotate leads outside of protection perido to queue ownership for example). For just the dashboard refresh use this:
 
Code:
<head>
<title>Dashboard Refresh</title>
<link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet">
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/dJS/en/1176317276000/library.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/031907/desktop/desktopAjax.js"></script>
<script type="text/javascript" src="/static/031907/js/functions.js"></script>
</head>

<BODY onLoad="bodyOnLoad();" >

<script type="text/javascript">
function bodyOnLoad() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '—m=poll&refresh=1', 'db_refresh_frame');
int = self.setInterval("refreshnow()",600000);
//int = self.setInterval("refreshnow()",100000);
}

function refreshnow() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '–m=poll&refresh=1', 'db_refresh_frame');
}
</script>

 Once you create the S-Control go to your dashboard and create a new component that is S-Control. I put no header, footer, and make the height 1, then stick that component at the bottom of the dashboard (it shows up as a line). In the S-Control it finds the ID of the dashboard using the URL and pageID variables, then the INT sets a variable to call the refreshnow function every X number of seconds. 600000 is about 10 minutes, turn it down to 100000 for testing and that refreshes every 5 minutes or so.
 
The only problem I have had with this code is if a user takes the dashboard and adds it to their homepage it won't refresh properly b/c the ID of the page is the homepage not the dashboard. If you want that to work hardcode the ID of the dashboard into the S-Control so it doesn't rely on the URL and pageID to know what to refresh.
This was selected as the best answer
chopairchopair
Thanks for help with this.  I will let you know how I get on.

Denis
chopairchopair
I cut and pasted your code into an s-control and I added that to one of my dashboards.  I then did a test.

I can see the browser come alive on queue but the date/time for the refresh is not being updated nor is the data contained in some of the report information that appears within the dashboard.  I am using firefox if that makes any difference.

Any suggestions?
chopairchopair
Just in case this is important, when the dashbaord is open and just sitting there on the page, the url actually displays https://na3.salesforce.com/01Z500000002yW5?m=view
chopairchopair
I made one change to one of your lines of code and now it seems to be working.  I changed the - to an ? as follows;

window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');
EEEEEE
Huh. In my code that dash is a question mark too. Seem like it changed that when I copy/paste into the text box on the site. Glad you got it working.
 
Also not sure why you're dashboard comes up with the m=view as when I pull up dashboard it's always just the ID. You could obviously add to that substring logic to just grab the 15 charachter ID after the / so you know you're just getting that ID and not any trailing text. I'm assuming that's probably what you did.
 
Happy auto-refreshing.......
MycodexMycodex
I was having a problem similar to chopair where the dashboard was placed into an infinite loop with this code. It only happens when the user either goes into Edit mode or exists Edit mode. I used the following code to bypass this. It simply makes sure that the dashboard URL does not contain 'preview' or 'view' (which were the 2 cases that were causing the loop).

I noticed that =view stays in the URL after the user exits Edit mode and then changes to a different dashboard. This means the user will have to manually remove the =view from the URL to cause other dashboards to automatically refresh. This isn't too big of an issue since the only users that will be editing a dashboard are administrators and they can be trained to watch for that. They don't care as much about the data as it is.

This was tested with IE 6.0, 7.0 and FF 3.0

Code:
<script type="text/javascript">
function bodyOnLoad() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
var pageloc = url.substring(url.lastIndexOf('='));
if (pageloc!="=preview")
{if (pageloc!="=view") {window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');}}
}
</script>

 



Message Edited by Mycodex on 07-16-2008 12:39 PM

Message Edited by Mycodex on 07-16-2008 12:41 PM
EEEEEE

Mycodex- I like that improvement. Thank you.

E

GeremyCPGeremyCP
I tried this - but it doesn't sppear to work. I copied the code above into an S-Control and adding that S-Control as a component on one of my dashboard.  No header/footer, set height to 1.  It adds a grey line at the bottom of the dashboard.  When I access that dashboard, it appears to be in a constant "reresh" loop for a few seconds - then it stops.  It never says "refreshing dashboard" at top right, and the "as of" date is still set to the last time I manually refreshed the dashboard.
 
Did I do something wrong?  Or is this code no longer good?
MycodexMycodex
GeremyCP, what web browser are you using? I can confirm this still works in IE6 and FF 3.0.1 as of 8/25/08.
 
Make sure your URL does not include "?m=preview" or "?m=view" since this causes the browser to sometimes go into the infinite loop you describe. Since users rarely go into these modes, it should not be a big deal.
 
As far as I can tell, Salesforce does not promote code or fixes into their systems unless they introduce a new API or enhancement. This code should work at least until the next release in October/November. By then, I hope they beef up their infrastructure and make this available to all users.
GeremyCPGeremyCP

Thanks for such a speedy response.  I'm using the following code as copied from the message board.  I did correct the two '-m instances to be '?m and I'm using IE 7.0.  When I click to the dashboard I can see at bottom left of screen (right above start menu) that the browser is constantly running a refresh or something.  My reports are very small, they take about 10 seconds on manual refresh.  So when this is looping for 2+min I assume it's not working correctly?

Code:
<head>
<title>Dashboard Refresh</title>
<link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet">
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/dJS/en/1176317276000/library.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/031907/desktop/desktopAjax.js"></script>
<script type="text/javascript" src="/static/031907/js/functions.js"></script>
</head>

<BODY onLoad="bodyOnLoad();" >

<script type="text/javascript">
function bodyOnLoad() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');
int = self.setInterval("refreshnow()",600000);
//int = self.setInterval("refreshnow()",100000);
}

function refreshnow() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');
}
</script>

 
MycodexMycodex
GeremyCP, you are using the code that includes setInterval. That function, for whatever reason, does not seem to work in IE properly. Do a google search and you'll find developers screaming that "it works in Firefox, Opera, and others, but not in Internet Explorer". Blame Microsoft.
 
When I posted my solution, I completely got rid of setInterval since I really didn't need to have the page refreshed every 10-60 minutes. A user usually accesses the page and then moves on. In its entirety, here is the code I use:
 
Code:
<head>
<title>Dashboard Refresh</title>
<link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet">
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/dJS/en/1176317276000/library.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/031907/desktop/desktopAjax.js"></script>
<script type="text/javascript" src="/static/031907/js/functions.js"></script>
</head>

<BODY onLoad="bodyOnLoad();" >

<script type="text/javascript">
function bodyOnLoad() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
var pageloc = url.substring(url.lastIndexOf('='));
if (pageloc!="=preview")
{if (pageloc!="=view") {window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');}}
}
</script>

 
Hope that works for you.


Message Edited by Mycodex on 08-25-2008 03:15 PM
rpr2rpr2
If anyone can figure out how to make the SetInterval part of the code (or provide alternative code) that would function in IE to do a refresh every x minutes, that would be great.  I am trying to find a way to do an automatic refresh of a dashboard that we have displayed on a large screen in our sales area.  Right now we have a manager who is tasked with manually refreshing it periodically.  If we could come up with a way to automate this is would be great.  Moving from IE to Firefox is not an option in my environment.
EEEEEE
Not sure why setInterval isn't working for you. The code with setInterval works for me with IE 7.  I think it worked in IE 6 too. I don't remember any isssues with that. We use this code for the exact reason you are describing with a "scoreboard" on each office's big screen with sales performance that refreshes every 15 minutes.
 
 
MycodexMycodex
rpr2: give the original solution a try and see what happens. Maybe EEE is right about it working for him, but for some reason it would not work for me or other users in my company. Could be our version of java or IE? Post your results once you test.
EEEEEE
Now that I'm thinking about this.....  We did have to disable toolbars, like the LIVE toolbar caused us problems. Strip down all the doo dads out of IE and see if that helps. For grins I went and hit a dashboard that has the below code and it worked fine refreshing every 15min or so.
 
Code:
<head>
<title>Dashboard Refresh</title>
<link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet">
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/dJS/en/1176317276000/library.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/031907/desktop/desktopAjax.js"></script>
<script type="text/javascript" src="/static/031907/js/functions.js"></script>
</head>

<BODY onLoad="bodyOnLoad();" >

<script type="text/javascript">
function bodyOnLoad() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');
int = self.setInterval("refreshnow()",600000);
}

function refreshnow() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');
}
</script>

 
 
E
rpr2rpr2
I tried the code last posted by EEE and it didn't work for me.  It refreshes when I initially go to the dashboard, and if I change pages and then return to the dashboard it refreshes.  However, if I remain on the page it does not.  What happens is that at the time that the refresh should occur I hear a "click" and a quick flash of the screen as if it is trying to refresh, but the "as of date/time" does not change.
 
As requested, I disabled the google toolbar that I generally have enabled in my browser, and every other add-on that I could find (I didn't have a whole lot), and shut down my browser session and then initiated a new one.  Still no go.  I also checked to make sure that the ? didn't get converted to a dash, as referenced earlier in the thread.
 
Now that I know it works for some people with IE I'm even more determine to get this working!  Definitely open to trying other things if anyone has any ideas. 
 
Rhonda
MycodexMycodex
rpr2: you are getting the same error I get although you do not see it because IE hides its errors from the user
 
Error: refreshnow is not defined
Source File: https://cs2.salesforce.com/servlet/servlet.Integration?lid=01NR00000008dMR&ic=1
Line: 22
 
You can try opening up IE's script debugger (Tools Menu > Options > Advanced tab > uncheck Disable Script Debugging (Internet Explorer) > OK > View Menu > Script Debugger) and viewing what error you get. This is when I run the following code:
 
Code:
timerID = self.setInterval("refreshnow()",30000);

function refreshnow() {
  var url = window.top.location.href;
  var pageid = url.substring(url.lastIndexOf('/'));
  var pageloc = url.substring(url.lastIndexOf('='));
  if (pageloc!="=preview")
    {if (pageloc!="=view") {window.open(pageid + '—m=poll&refresh=1', 'db_refresh_frame');}
  }
} 

 I'm not familiar 100% with javascript but countless websites on setInterval initialize the function in the same manner. EEE, any chance you can provide some assistance?
EEEEEE

I went back and looked at some of the email I sent out to admins to configure machines to get this to work right and came up with a couple things. I always assume anyone using SF has these IE settings tweaked as they constantly cause us issues if they aren't.....  That browsing history setting is a probably the issue if it's set to AUTOMATIC.....

E

On the machine open Internet Explorer and go to TOOLS + INTERNET OPTIONS....  Click the Browsing History SETTINGS button and verify the Temporary Internet Files and History Settings is set to check for newer versions of stored pages "Every time I visit the webpage"....  Next go to TOOLS + POP UP BLOCKER + POP UP BLOCKER SETTINGS and uncheck the option to "show information bar when pop up blocked".

 

 

rpr2rpr2

BINGO!

Thank you, EEE.  I recently started using a new computer and hadn't done all the Salesforce.com browser configurations that are recommended.

Here they are if anyone else is looking for the full set:

https://na1.salesforce.com/_ui/training/help/pub/UserEdSolution?id=50130000000KUf4&retURL=https%3A%2F%2Fna5.salesforce.com%2F_ui%2Ftraining%2Fhelp%2FCombinedSearchPage%3Fstr%3Dbrowser%2Bsettings&ps=1&orgId=00D000000000062

Rhonda

 

Justin PRJustin PR
Does anyone know how to make this script not make your window take focus? I leave the dashboard open on another window but each time the dashboard refreshes (which is every 5 mins), the window takes focus and I have to click back to whatever I was working on.
EEEEEE
Not sure you're going to get around that. For dashboards you use regularly change the code to just refresh on load, and have two different scontrols that depending on the type of dashboard and process you can include one or the other. At least that's what I do. Or if someone wants to post a trigger that does this kind of thing I've been meaning to get on that for months. What we do in dashboard refresh I believe could be done with triggers or outbound msgs depending on the scenario.
SesameStreetSesameStreet

Dear EEE,

 

I've used your S-Control and it worked like charm.

I'd also like to activate this refresh capability in the home page, but since I'm not a developer I do not know where I should hard code the url.

I'd be much obliged if you could guide me how to find the url and where to paste it into the code.

 

Thank you!

EEEEEE

SS, take a look at the first post and the code snippet there....  If I remember right with the home page you create your home page dashboard and make one of the compnents the s-control that is going to call the code to refresh automtically and then you hard code the dashboard id in the window open, something like the below. I don't use it on the home page anymore so that isn't top of mind.......

 

window.open('/01Z6000000073av—m=poll&refresh=1', 'db_refresh_frame');

 

 

rpr2rpr2

I know this is an old thread but it is one of my all-time favorites.  I'm not a developer so I don't understand HOW the code provided here works, but when I added it for my users they love it.  Until this week that is.  Now, several users are getting this message pop up:  

Unable to Access Page

Invalid parameter value "POLL" for parameter "m".

Error: The value of the parameter specified above contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and re-submit. If the error still persists, please report it to our Customer Support team and provide the URL of the page you were requesting as well as any other related information.

I did not change anything on my end, although we did have our org get upgraded to the Winter '11 release last weekend.

 

It doesn't occur on my computer, so I suspected browser settings and went through the salesforce recommended settings on one of my end-user systems, and it didn't fix it.  Still suspecting browser settings since it doesn't happen on my computer, but not sure which setting it may be.  We use Internet Explorer -- and don't have choice of changing.

 

Any ideas of how to address this error message?

Here's the specific line in the code which seems to be referred to in the message:

 

window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame'); 

 

EEEEEE

rpr2 replace that original window.open line with the one below and that got it working again.

 

//window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');

 

to

 

window.open.location = '/'+pageid +'?customAutoRefresh=1';

// 10/13/10 - changed the call from m=poll to ?customAutoRefresh b/c of errors with WinterRelease 2011

rpr2rpr2

@EEE - Thanks for the quick response!  Making the change you provided got rid of the original error message, but the dashboard didn't refresh, and I noticed that IE had the error icon at the bottom of the screen.  Here's what was in the details:

 

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.6;  Embedded Web Browser from: http://bsalsa.com/; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Fri, 15 Oct 2010 06:18:39 UTC


Message: Object doesn't support this property or method
Line: 19
Char: 1
Code: 0
URI: https://na5.salesforce.com/servlet/servlet.Integration?lid=01N70000000AQvQ&ic=1&autoMapValues=1

 

I'm pasting in the entire code I'm using so you can see if some other line also needs to be changed.

 

<head>
<title>Dashboard Refresh</title>
<link href="/dCSS/Theme2/default/common.css" type="text/css" rel="stylesheet">
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="/dJS/en/1176317276000/library.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/031907/desktop/desktopAjax.js"></script>
<script type="text/javascript" src="/static/031907/js/functions.js"></script>
</head>

<BODY onLoad="bodyOnLoad();" >

<script type="text/javascript">
function bodyOnLoad() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
//window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');
window.open.location = '/'+pageid +'?customAutoRefresh=1';
// 10/13/10 - changed the call from m=poll to ?customAutoRefresh b/c of errors with WinterRelease 2011
int = self.setInterval("refreshnow()",600000);
}

function refreshnow() {
var url = window.top.location.href;
var pageid = url.substring(url.lastIndexOf('/'));
//window.open(pageid + '?m=poll&refresh=1', 'db_refresh_frame');
window.open.location = '/'+pageid +'?customAutoRefresh=1';
// 10/13/10 - changed the call from m=poll to ?customAutoRefresh b/c of errors with WinterRelease 2011
}
</script>

 

 Rhonda

MaxaMaxa

HI, i'm having exactly the same problem, any ideas on solution?

MaxaMaxa

if i paste this line to the IE 'javascript&colon;sfdc.analytics.quickfind.refresh%28false%29'

it does refresh ok

maybe this would be of any help , problem when i try to incorporate it into script it deos not work becasue it opens new window, any idea how to open the script in the existing window?>

gdhgdh

I'm having the same problem as well,  the error ,Invalid parameter value "POLL" for parameter "m". has been corrected but the dashboard doesn't refresh.  Has anyone found a solution that has worked for them yet?

 

gbu_jinigbu_jini

As we're not allowed to create S Controls anymore, do you know another way to perform the auto refresh ?