You need to sign in to do that
Don't have an account?

Increment counter, save value and rerender on page
I used this code as is (borrowed from visualforce documentation) on my sites page.
It's labeled "update" and everytime it clicks, the value increments
However when the sites page is refreshed, it resets to zero.
What I need is to save the value everytime it increments to a field called "#ofUpdates" because I'd like to display this value alongside the counter link on the sites page.
How do I go about modifying the code to achieve this? Any help would be greatly appreciated.
<apex:page controller="exampleCon">
<apex:form >
<apex:outputText value="Update: {!count}" id="counter"/>
<apex:actionStatus id="counterStatus">
<apex:facet name="start">
<img src="{!$Resource.spin}"/> <!-- A previously defined image -->
</apex:facet>
</apex:actionStatus>
<apex:actionPoller action="{!incrementCounter}" rerender="counter"
status="counterStatus" interval="7"/>
</apex:form>
</apex:page>
Controller
public class exampleCon {
Integer count = 0;
public PageReference incrementCounter() {
count++;
return null;
}
public Integer getCount() {
return count;
}
}
If you want to save the counter so that if you start next time it starts from last count, you have to save count every time it gets increased , I saved this in Account Objects NumberOfEmplyee field you can use any other field or custom setting.
https://c.ap1.visual.force.com/apex/IncrementCounterPage
Apex Class
VFP
You can see this on here on my site page
https://c.ap1.visual.force.com/apex/IncrementCounterPage
You can see this on here on my site page
All Answers
Here it is on my site page
http://metacubepoc-developer-edition.ap1.force.com/IncrementCounterPage
Working fine
If your issue is that when you refresh the page by hitting URL again then it will rest to zero as no view state will be there then.
Here is my code
Apex Class:
VFP
Please let me know if I could not get you issue.
If you want to save the counter so that if you start next time it starts from last count, you have to save count every time it gets increased , I saved this in Account Objects NumberOfEmplyee field you can use any other field or custom setting.
https://c.ap1.visual.force.com/apex/IncrementCounterPage
Apex Class
VFP
You can see this on here on my site page
https://c.ap1.visual.force.com/apex/IncrementCounterPage
You can see this on here on my site page
Thanks so much. This is exactly what i needed.