+ Start a Discussion
Mateo AlcauterMateo Alcauter 

how to call a function on page load

I have this button that calls a function. How can i call this function (filterTransactions) when the page first loads?
I tried this, but it does not work.
<apex:page controller="CommunityPostedTransactionsController" action="{!filterTransactions}" showHeader="false" sidebar="false" cache="false">

Here is the button code:
<apex:commandButton action="{!filterTransactions}" value="Filter" rerender="output,selectListPanel, exportCSV" immediate="false"></apex:commandButton>

 
srlawr uksrlawr uk
The "action" markup is correct, so I don't know why it isn't firing the method. When you say it does not work, do you get an error message? or any behavior to report at all?

You can't have DML in a method called from an Action invocation, but I think that throws you a very specific message to that effect.

You might be able to use an ActionFunction to do this? An Actionfunction lets you tie an apex method call to a javascript function, so you can then call the actionfunction (javascript method) from your favourite page onload() method (normal markup or jQuery if you fancy).