If you need the count to be updated in your Apex controller in real time (i.e., upon each button click), you can use either JavaScript Remoting to asynchronously update the Account Sobject, or use an <apex:actionFunction>
component to use JavaScript to call your controller to make updates.
The <apex:actionFunction>
component creates a JavaScript function that you can call to invoke in order to fire a Visualforce controller action. Additionally, you can supply parameters, which are assigned to Visualforce controller instance variables. Example:
<apex:actionFunction action="{! updateCount }" name="updateCountJS ">
<apex:param name="count" assignTo="{! clickCount }" value="" />
</apex:actionFunction>
This defines a function updateCountJS(count)
that you can call in JavaScript, which calls the action method updateCount()
in your controller. At that time, the parameter of the JavaScript function would be assigned to the clickCount
instance variable in the controller. Your Apex action method can then assign that data to an Account sobject variable or take other action.
JavaScript Remoting requires that the Apex method you call be static
, meaning it cannot access the controller's state. To go that route, you'd define a method something like this on your controller:
@RemoteAction
global static void updateCount(Id accountId, Integer count) {
// Perform work here to query account and update count.
}
Then, in the Visualforce page's JavaScript, invoke the method:
ControllerName.updateCount('{! a.Id }', count);
These examples are a little bit fuzzy - I am not sure how you're maintaining a count of clicks on a link that appears to navigate away from the page - but I believe something along these lines will suit the situation. Please excuse the terseness of my original answer, which did not provide enough information to be especially useful.