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
megsumamegsuma 

Passing Parameters to Apex without Interaction

Is it possible to pass a parameter to an Apex page without the user having to perform an action (such as clicking a button or link)? Essentially, the idea would be to have a VF page that takes a parameter from the query string and passes it to the apex controller when my getter function is called. Page is something like this:

 

<apex:page controller="CompanyStatsDashboardController"> ...Some javascript to get the query string parameter... <apex:image url="{!UserCountChart}"></apex:image> </apex:page>

 The reason I can't just call something like System().currentPageReference().getParameters().get() is because the VF page lives on a Dashboard, and as such renders in an iFrame. The iFrame has it's own URL that does not contain the parameter, and as far as I can tell you can't tell the Dashboard to pass parameters to the VF page. I've also tried setting an <apex:param> with the value I want to pass and using apexPages().currentPage().getParameters(), but this doesn't work either. 

 

 

hokusaihokusai
I have had a similar problem and I had to give up try another approach
Rajesh ShahRajesh Shah
Have you tried using Action Poller? Basically when your page loads the Action Poller would be active and call a controller. I am not sure if the param can be used with action poller, but in case it isn't supported, you can call a JavaScript function from Action Poller and the JS function can pass parameter to the controller.
megsumamegsuma

Yet again I figured it out in about the best way I could, which unfortunately seems a little sloppy. Basically, I added some javascript to check for the parameter company_id in the iframe's query string - if it can't find it, it grabs the company_id from the parent (Dashboard) query string and reloads the iframe with the company_id parameter attached to the iframe URL, so...something like this:

 

 

<apex:page controller="myController"> <script> function get_param(what)

{

...

}

 

if(document.location.href.indexOf('company_id') <= 0) { document.location.href = '/apex/myVFPage?company_id='+get_param(company_id); }

</script> .... </apex:page>

 

This allows the VF page, even in an iframe in the Dashboard, to recieve the necessary parameter from the Dashboard's URL. Quite annoying, but the only solution I've found so far. Oh, and I set the sidebar and other options in the page definition to false so the only thing that shows on the VF page is the image itself, none of the other Salesforce stuff, so it fits perfectly in a 400x400 box in a Dashboard.